所以我有這個表:創建觸發器刪除行
CREATE TABLE orders_rows (
order_id NUMBER(10) PRIMARY KEY,
row_num DATE NOT NULL,
p_id NUMBER(10) NOT NULL,
quantity NUMBER(10) NOT NULL,
);
我想創建一個觸發器,當更新改變量爲0(零) - >刪除此列。
我嘗試這樣做:
CHECK_ORDER_ROW trigger:
create or replace
TRIGGER check_order_row
AFTER INSERT OR UPDATE on orders_rows
for each row
BEGIN
if :new.quantity = 0 then
DELETE_ORDER_ROW(:new.order_id, :new.row_num);
end if;
END;
DELETE_ORDER_ROW是具體的步驟:
DELETE_ORDER_ROW procedure:
create or replace
PROCEDURE delete_order_row (p_order_id NUMBER, p_row_num NUMBER)
IS
BEGIN
DELETE orders_rows WHERE (order_id = p_order_id and row_num = p_row_num);
COMMIT;
END;
但是,當我嘗試更新:
update orders_rows set quantity=0 where (order_id=1 and row_num=1);
我收到的錯誤:
A trigger (or a user defined plsql function that is referenced in
this statement) attempted to look at (or modify) a table that was
in the middle of being modified by the statement which fired it.
我能做的任何更改嗎?或嘗試其他選項來做到這一點?
在此先感謝!
這是你正在談論的遞歸觸發器。不要以爲Oracle支持一個。 – Rahul 2015-03-31 18:28:20