0
在下面的觸發器中,在使用duplicate_info異常時並未在begin塊中引發它,我不確定這是如何工作的。當其他人也不例外,但是這個duplicate_info例外有效。奇怪!在Oracle觸發器中用戶定義的異常
CREATE OR REPLACE TRIGGER ORDER_INFO_T
INSTEAD OF INSERT ON order_info
DECLARE
duplicate_info EXCEPTION;
PRAGMA EXCEPTION_INIT (duplicate_info, -00001);
BEGIN
INSERT INTO customers
(customer_id, cust_last_name, cust_first_name)
VALUES (
:new.customer_id,
:new.cust_last_name,
:new.cust_first_name);
INSERT INTO orders (order_id, order_date, customer_id)
VALUES (
:new.order_id,
:new.order_date,
:new.customer_id);
EXCEPTION
WHEN duplicate_info THEN
RAISE_APPLICATION_ERROR (
num=> -20107,
msg=> 'Duplicate customer or order ID');
END order_info_insert;
/