帶游標的儲存過程例子,很經典

2021-06-07 03:23:43 字數 4035 閱讀 1813

create

or replace

procedure sum_storage    

isplant  g_containerinv.plant%type;   

sloc   g_containerinv.sloc%type;   

part   g_containerinv.partno%type;   

qty    g_containerinv.qty%type;   

cursor c_sumqty   

isselect plantid,whid,partno,sum

(qtyperuom) as totalqty from g_container group

by plantid,whid,partno;   

vr_intoqty   c_sumqty%rowtype;               

begin

open c_sumqty;   

loop   

fetch c_sumqty   into vr_intoqty;   

exit when c_sumqty%notfound;   

plant:  = vr_intoqty.plantid;   

sloc:  = vr_intoqty.whid;   

part:  = vr_intoqty.partno;   

qty:  = vr_intoqty.totalqty;   

insert

into g_containerinv(timekey, plant, sloc, partno, qty, editdate, operater)    

values (to_char(sysdate,'yyyymmddhh24miss'),plant,sloc,part,qty,sysdate,'wms');   

end loop;   

close c_sumqty;   

commit;   

end sum_storage;   /

例子2

create

or replace

procedure add_sup_temp is

v_group_id  sup_temp.group_id % type;   

v_item_id   sup_temp.item_id % type;   

v_item_name sup_temp.item_name % type;   

v_cnt_group number(4);   

cursor c_product_group is

select group_id, item_id, lang, item_name, classify_id, parent_item   

from viewa;   

cursor c_groupcursor(p_group_id sup_acl_product_group.group_id % type) is

select group_id from tableb;   

begin

delete

from sup_acl_product_group;   

open c_product_group;   

loop   

fetch c_product_group   

into v_group_id, v_item_id, v_item_name;   

exit when c_product_group%notfound;   

open c_groupcursor(v_group_id);   

loop   

fetch c_groupcursor   

into v_c_group_id;   

exit when c_groupcursor%notfound;   

select

count

(group_id)   

into v_cnt_group   

from sup_acl_product_group pg   

where pg.group_id = v_c_group_id   

and pg.item_id = v_item_id;   

if v_cnt_group <> 0 then

update sup_acl_product_group pg set pg.last_update_time = sysdate;   

else

insert

into sup_acl_product_group   

(group_id, item_id, item_name, last_update_time)   

values

(v_c_group_id, v_item_id, v_item_name, sysdate);   

end if;   

end loop;   

close c_groupcursor;   

end loop;   

close c_product_group;   

commit;   

end;

例子3

create

or replace

procedure p_tmp   

begin

declare

cursor c_cur is

select  st.business_id            as business_id,   

st.userid       as userid,   

st.end_date        as end_date,   

st.creation_date  as creation_date   

from tableh st   

where 1=1;   

v_row                c_cur%rowtype;   

v_business_id_t      varchar2(200);   

begin

open c_cur;   

loop   

fetch c_cur   

into v_row;   

exit when c_cur%notfound;   

select

count

(n.business_id)   

into v_business_id_t   

from tablem n   

where n.business_id = v_row.business_id   

and n.userid = v_row.userid;   

if v_business_id_t = 0 then

insert

into tablen   

(business_id, userid, end_date, creation_date)   

values

(v_row.business_id,   

v_row.userid,   

v_row.end_date,   

v_row.creation_date);   

end if;   

if v_business_id_t > 0 then

update tablen t   

set t.end_date = v_row.end_date   

where t.business_id = v_row.business_id   

and t.userid = v_row.userid;   

end if;   

end loop;   

close c_cur;   

commit;   

end;   

exception   

when others   

then

rollback;   

dbms_output.put_line('異常啦');   

end;

oracle帶游標的儲存過程

create or replace procedure xs test add19 is bachelor edu varchar2 2000 new bachelor edu varchar2 2000 aa varchar2 2000 bb varchar2 2000 edu length in...

oracle 帶游標的儲存過程

如果各位以前從來沒有寫儲存過程,可得仔細了,因為在進行儲存過程編寫的時候,新手很容易出錯,非常容易。執行儲存過程各個oracle客戶端是不是樣的 可能你在網上看到的是呼叫exec,但是你再怎以呼叫你都執行不了,原因何在,因為exec是pl sql develop裡面的乙個程式,而你當前使用oracl...

帶游標的儲存過程 ibatis 呼叫方法

begin select t.type,t.orglevel into v type,v orglevel from sys organize info t where t.id ai forgid if v type 03 and v orglevel 04 then open out cur f...