I'm trying to create a table within a procedure. This is a table I'm going to want to re-create on a regular basis which is why I thought a procedure would be the best way to go.
My code looks like this:
Any help would be really hugely appreciated.
Thanks in advance....
Fi.
"The question should be, is it worth trying to do, not can it be done"
My code looks like this:
Code:
create or replace procedure proc_locale
as
begin
begin
execute immediate 'drop table Locale';
exception
when others then
if sqlcode = -942 then
null; -- table does not exist
else
raise;
end if;
end;
CREATE TABLE Locale
as
SELECT
d.ONEKEY_TYPE_ETA as DestETA,
d.ONEKEY_PHARMACY_CODE as DestCODE,
d.Address1 as DestAdd,
d.Address2 as DestAdd2,
d.Address3 as DestAdd3,
d.OUTER_POSTCODE as DestOUTER,
d.INNER_POSTCODE as DestINNER,
d.GEO_X as DX,
d.GEO_Y as DY,
o.ONEKEY_TYPE_ETA as OrigETA,
o.ONEKEY_PHARMACY_CODE as OrigCODE,
o.Address1 as OrigAdd,
o.Address2 as OrigAdd2,
o.Address3 as OrigAdd3,
o.OUTER_POSTCODE as OrigOUTER,
o.INNER_POSTCODE as OrigINNER,
o.GEO_X as OX,
o.GEO_Y as OY,
(SQRT ((POWER ((o.GEO_X - d.GEO_X),2)) + (POWER ((o.GEO_Y - d.GEO_Y),2)))/1000)*0.621 as Miles,
(SQRT ((POWER ((o.GEO_X - d.GEO_X),2)) + (POWER ((o.GEO_Y - d.GEO_Y),2)))/1000) as Km
FROM
dol.pharmacy d, dol.pharmacy o
WHERE
(SQRT ((POWER ((o.GEO_X - d.GEO_X),2)) + (POWER((o.GEO_Y - d.GEO_Y),2)) )/1000)*0.621 < 10
AND
(d.Status = '3')
AND
(o.Status = '3')
AND
(d.TypETA = N'RCH')
AND
(o.TypETA = N'SUR')
AND
(o.ONEKEY_PHARMACY_CODE = o.MANAGING_INSTITUTION)
AND
(o.GEO_X + o.GEO_Y <> '0')
AND
(o.GEO_X is not null)
AND
(o.GEO_Y is not null)
end proc_locale;
Any help would be really hugely appreciated.
Thanks in advance....
Fi.
"The question should be, is it worth trying to do, not can it be done"