我有如下表在其他表執行刪除和更新各行
CREATE TABLE A2SKU
(
SKUID NUMBER NOT NULL,
SKUNAME VARCHAR2(20),
SKUQTY NUMBER,
CONSTRAINT A2SKU_PK PRIMARY KEY (SKUID)
);
CREATE TABLE A2LOC
(
LOCID NUMBER NOT NULL,
LOCNAME VARCHAR2(20),
LOCQTY NUMBER,
MAXQTY NUMBER,
CONSTRAINT A2LOC_PK PRIMARY KEY (LOCID)
);
Create Table A2BOX (
boxId NUMBER Primary Key,
skuId NUMBER,
locId NUMBER,
constraint FK_A2BOX_SKUID foreign key (skuid) references A2SKU,
constraint FK_A2BOX_LOCID foreign key (locid) references A2LOC
);
CREATE SEQUENCE A2BOXSEQ;
我想與匹配的SKU從A2Box表中刪除所有箱子和調節匹配位置的LocQty在A2Loc表每個盒子的數量除以1
我如何使用存儲過程來做到這一點。
我想我和這個
create or replace procedure A2DeleteSKU
(
pskuid IN number
)
AS
CURSOR row_cursor IS
SELECT boxid,locid from A2BOX where skuid = pskuid;
skuid_count Number;
skuid_check exception;
sku_rec row_cursor%rowtype;
Begin
select count(*) into skuid_count from A2SKU where skuid = pskuid;
if skuid_count <1 then
raise skuid_check;
End If;
FOR sku_rec in row_cursor
LOOP
delete from a2box where boxid = sku_rec.boxid;
update A2LOC set locqty = locqty -1 where locid = sku_rec.locid;
END LOOP;
delete from A2SKU where skuid =pskuid;
commit;
Exception
When skuid_check then
RAISE_APPLICATION_ERROR(-20014, 'Delete Box failed. Boxid does not exist: '||TO_CHAR(pskuid));
When others then
raise;
End A2DeleteSku;
您正在使用哪個dbms? – Tim