oracle 函式呼叫儲存過程操作

2021-09-01 21:43:42 字數 3369 閱讀 2231

create or replace function fun_plan_station_contrast(groupid varchar2)

return number is

tmp varchar2(200);

mycur sys_refcursor;

res number :=0;--不符合條件的記錄條數

type station_record is record(

strcode varchar2(200),

strname varchar2(200),

planquantity number(19,2),

configstock number(19,2),

configquantity number(19,2),

stockquantity number(19,2)

);--定義新型別來存放儲存過程返回的結果

tmp_record station_record;

begin

tmp := 'call plan_station_contrast(:param1,:param2) ';

execute immediate tmp using groupid,out mycur ;--呼叫儲存過程

--游標預設已開啟,因為儲存過程中是open refcursor for

if(mycur%isopen) then

dbms_output.put_line('開啟');

else

dbms_output.put_line('關閉');

end if;

loop

fetch mycur into tmp_record;

exit when mycur%notfound;

if tmp_record.planquantity<>tmp_record.configquantity or tmp_record.stockquantity<>tmp_record.configstock then

res:=res+1;

end if;

end loop;

close mycur;--關閉游標

return res;

end fun_plan_station_contrast;

create or replace procedure plan_station_contrast(

groupid in varchar2 ,--到站計畫主表id,非空

refcursor out sys_refcursor)

isplandate varchar2(6);--計畫年月

deptcode varchar2(10);--上報單位編碼

begin

select p.plan_date,p.dept_code into plandate,deptcode from p_station_group p where id=to_number(groupid);

open refcursor for 'select nvl(station.oil_code,config.oil_code) oilcode,nvl(station.oil_name,config.oil_name) oilname

,nvl(station.planquantity,0) planquantity --到站上報

,nvl(station.configstock,0) configstock --外採上報

,nvl(config.configquantity,0) configquantity --直煉配置

,nvl(config.stockquantity,0) stockquantity --外採配置

from

--到站計畫

(select p.oil_code,p.oil_name

,sum(plan_quantity)-sum(special_quantity) planquantity

,sum(stock_quantity) configstock

from

(select oil_code,oil_name

,decode(special,''0'',nvl(train_quantity, 0) + nvl(ship_quantity, 0)+ nvl(pipeline_quantity, 0) +nvl(truck_quantity, 0),0)plan_quantity

,decode(special,''1'',nvl(train_quantity, 0),0) special_quantity

,decode(special,''2'',nvl(train_quantity, 0) + nvl(ship_quantity, 0)+ nvl(pipeline_quantity, 0) +nvl(truck_quantity, 0),0) stock_quantity

from p_station where sid = '||groupid||'

)pgroup by p.oil_code,p.oil_name) station

full join

--配置計畫

( select p.oil_code,p.oil_name

,sum(decode(a.dtype,''factory'',decode(a.f_type,1,p.plan_quantity,0),''stock'',0,p.plan_quantity)) configquantity --配置量

,sum(decode(a.dtype,''factory'',decode(a.f_type,1,0,p.plan_quantity),''stock'',p.plan_quantity,0)) stockquantity --外採量

from p_disbtn p

left outer join p_config_plan_flow f on p.flow_code=f.flow_code --關聯配置計畫流向

left outer join acc_domain a on p.company_code=a.code

where bill_month='''||plandate||'''

and (select status from p_disbtn_group where bill_month='''||plandate||''')=''2''

and f.company_code='''||deptcode||'''

and p.plan_quantity>0

group by p.oil_code,p.oil_name

) config

on station.oil_code=config.oil_code ';

end plan_station_contrast;

Oracle儲存過程呼叫儲存過程

oracle儲存過程呼叫有返回結果集的儲存過程一般用光標的方式,宣告乙個游標,把結果集放到游標裡面,然後迴圈游標 declare newcs sys refcursor cs1 number cs2 number cstype table rowtype table列的個數和newcs返回的個數一樣...

oracle儲存過程和函式的呼叫

oracle儲存過程和函式的呼叫 建立儲存過程 create or replace procedure pro add num1 number,num2 number,r out number asbegin r num1 num2 end www.2cto.com create or replac...

C 呼叫oracle儲存過程

建立oracle過程儲存 create or replace procedure proce test paramin in varchar2,paramout out varchar2,paraminout in out varchar2 asvarparam varchar2 28 begin ...