oracle儲存過程

2021-09-01 06:56:23 字數 1889 閱讀 1075

create or replace procedure update_hb_order_state is

--**卡

cursor funds_ssk--前一天**卡支付金額

isselect t.order_id as order_id,is_reconciliation

from hb_order_settle t where t.settle_type = 2

and to_char(t.settle_time, 'yyyy-mm-dd') = to_char(sysdate - 1, 'yyyy-mm-dd');

cursor cusor_a--前一天**卡支付金額根據訂單號分組

isselect t.order_id as order_id

from hb_order_settle t where t.settle_type = 2

and to_char(t.settle_time, 'yyyy-mm-dd') = to_char(sysdate - 1, 'yyyy-mm-dd') group by t.order_id;

--兌換卡

cursor funds_ddk--前一天兌換卡支付金額

isselect t3.id as order_id

from hb_goods_card t1, hb_goods_card_type t2, hb_order t3

where to_char(t1.change_time, 'yyyy-mm-dd') = to_char(sysdate - 1, 'yyyy-mm-dd')

and t1.type_code = t2.type_code and t3.goods_card_num = t1.card_num;

--實物銷售

cursor funds_swss--前一天的實物銷售資料

isselect t.id as order_id from hb_order t where t.order_type = 4

and to_char(t.insert_time, 'yyyy-mm-dd') = to_char(sysdate - 1, 'yyyy-mm-dd');

recon number;--1未對賬

begin

--如果**卡支付全部已對賬則將主訂單對賬狀態改為0

for a in cusor_a loop

--判斷是否全部已對賬

for b in funds_ssk loop

if a.order_id = b.order_id

then

if b.is_reconciliation <> 0--如果這組訂單包含未對賬的

then

recon := 1;

end if;

end if;

end loop;

if recon <> 1

then

update hb_order t set t.is_reconciliation = 0 where t.id = a.order_id;

end if;

end loop;

--兌換卡

for o in funds_ddk loop

update hb_order t set t.is_reconciliation = 0 where t.id = o.order_id;

end loop;

--實物銷售

for o in funds_swss loop

update hb_order t set t.is_reconciliation = 0 where t.id = o.order_id;

end loop;

commit;

end update_hb_order_state;

Oracle儲存過程呼叫儲存過程

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

ORACLE儲存過程

自定義函式開始 create or replace function fn wftemplateidget templatecategoryid number,organid number,templatemode number return number istemplateid number i...

Oracle 儲存過程

create or replace procedure p 有就替換,沒有就建立 iscursor c is select from emp for update begin for v emp in c loop if v emp.deptno 10 then update emp2 set sa...