包含方法的ORACLE儲存過程

2021-05-25 12:03:35 字數 2071 閱讀 2514

procedure p_get_picking (vn_orderid varchar2)

asvn_sumqty   number (8);                                        --分配的庫存總和

vr_order    wm_order_out_material%rowtype;                      --單行訂單物料

vr_inv      wm_mat_inventory%rowtype;                             --單行庫存

cursor c_order

isselect *

from wm_order_out_material

where order_id = vn_orderid;                       --定義游標取出該訂單下的所有物料

cursor c_inv (vn_mat_id varchar2)                           --定義游標取出物料庫存

isselect i.*

from wm_mat_inventory i

where i.mat_id = vn_mat_id

order by i.create_date;

begin

delete from wm_order_out_picking

where order_id = vn_orderid;

open c_order;

loop

fetch c_order into vr_order;                                 --迴圈訂單物料

exit when c_order%notfound;

vn_sumqty := 0;

open c_inv (vr_order.mat_id);                             --取出符合條件的庫存

loop

fetch c_inv into vr_inv;     -- 遍歷取出庫存中的物料

exit when c_inv%notfound;

if vn_sumqty < vr_order.quantity                -- 如果總數量小於訂單數量

then

if vr_inv.qty_balance is null or vr_inv.qty_balance = 0 

then

exit;

end if;

vn_sumqty := --記錄總數量

vn_sumqty + vr_inv.qty_balance

- (case

when vr_inv.qty_output is null then 0

else vr_inv.qty_output

end);

insert into wm_order_out_picking (mat_serial,           --插入揀貨表

quot_id,

mat_id,

quantity,

loc_id,

order_id)

values (

f_next_picking_id,

vr_inv.quot_id,

vr_inv.mat_id,

(case

when vn_sumqty > vr_order.quantity

then

vr_order.quantity

- (vn_sumqty

- (vr_inv.qty_balance

- vr_inv.qty_output))

else

vr_inv.qty_balance - vr_inv.qty_output

end),

vr_inv.loc_id,

vr_order.order_id);

commit;

end if;

end loop;

close c_inv;

end loop;

close c_order;

end;

C 呼叫Oracle儲存過程的方法

準備 環境 pl sql oracle9i vs2008 建立表test create table test id number,編號 name varchar2 10 姓名 varchar2 2 性別 age number,年齡 address varchar2 200 住址 1.執行不帶引數的o...

C 呼叫Oracle儲存過程的方法

準備 環境 pl sql oracle9i vs2008 建立表test create table test id number,編號 name varchar2 10 姓名 varchar2 2 性別 age number,年齡 address varchar2 200 住址 1.執行不帶引數的o...

C 呼叫Oracle儲存過程的方法

準備 環境 pl sql oracle9i vs2008 建立表test create table test id number,編號 name varchar2 10 姓名 varchar2 2 性別 age number,年齡 address varchar2 200 住址 1.執行不帶引數的o...