create or replace package welldailycross is
type ref_cursor is ref cursor; --建立帶返回的游標
procedure prowelldailycross(starttime in varchar2,endtime in varchar2, orgid in varchar2,my_ref_cursor out ref_cursor);
end welldailycross;
create or replace package body welldailycross is
procedure prowelldailycross(starttime in varchar2,endtime in varchar2,orgid in varchar2,my_ref_cursor out ref_cursor) is
begin
declare
*** number;
sqlstr1 varchar2(1000);--建立臨時表
sqlstr2 varchar2(1000);--插入資料
sqlstr3 varchar2(1000);--查詢臨時表
usertotal varchar2(20); --使用者得到和所有
datenow varchar2(20); ---時間
org_id varchar2(10);--機構編號
orgname varchar2(20);--機構名稱
cursor alldate is
select rownum,(to_date(starttime,'yyyy-mm-dd')+rownum-1) times
from dual connect by rownum<= to_date(endtime,'yyyy-mm-dd')-to_date(starttime,'yyyy-mm-dd') +1;--查詢開始時間和結束時間這間所有時間
curdate alldate%rowtype;
begin
select count(*) into *** from user_tables where table_name = 'temp_tab2';
sqlstr1 := 'create global temporary table temp_tab2(
usertotal varchar2(20),
datenow varchar2(20),
org_id varchar2(10),
orgname varchar2(20)
)on commit delete rows';
if *** = 0 then
execute immediate 'grant create table to omsdata';
execute immediate sqlstr1;
end if;
open alldate;
loop
begin
fetch alldate into curdate;
exit when alldate%notfound;
select nvl(sum(x.oiltotal+y.otherstotal),0) as total,
x.nowtime as nowdate into usertotal,datenow
from
(select
nvl(sum(toi.scyyl1+toi.scyyl2),0) as oiltotal ,
to_char(curdate.times,'yyyy-mm-dd') as nowtime
from
tab_oil_info toi
where toi.org_id=orgid and toi.acq_date=to_char(curdate.times,'yyyy-mm-dd'))x,
(select
nvl(sum(tsu.tsyyl),0) as otherstotal
from
tab_spec_use tsu
where tsu.org_id=orgid
and tsu.acq_date =to_char(curdate.times,'yyyy-mm-dd'))y group by x.oiltotal,x.nowtime;
select toi.org_name into orgname from tab_org_info toi where toi.org_id=orgid;
sqlstr2 := 'insert into temp_tab2 values('''||usertotal||''','''||datenow||''','''||orgid||''','''||orgname||''')';
execute immediate sqlstr2;
end;
end loop;
sqlstr3 := 'select * from temp_tab2';
open my_ref_cursor for sqlstr3;
--loop
--begin
-- fetch my_ref_cursor into usertotal,datenow,org_id;
-- exit when my_ref_cursor%notfound;
-- dbms_output.put_line('日期'||datenow||'每天總收油量:'||usertotal||'每天用油總量'||org_id);
-- end;
-- end loop;
end;
end prowelldailycross;
end welldailycross;
oracle帶返回值的儲存過程
create table tb storage id number 9 shopid varchar 10 storage number 10 not null table created create table tb shop id number 9 shopid varchar 10 shop...
PB呼叫帶返回引數的儲存過程
string ls doc no declare sp generate doc no procedure for sp generate doc no comp code comp code,doc type doc type,doc month doc month,doc year doc ye...
oracle帶返回值的儲存過程
create table tb storage id number 9 shopid varchar 10 storage number 10 not null table created create table tb shop id number 9 shopid varchar 10 shop...