我寫了觸發器來檢查客戶是否有任何暫停的帳戶。如果是,他將無法創建新帳戶,但是當我嘗試插入時,插入仍然會通過。有人可以幫助我嗎?觸發器和計數(*)不起作用
CREATE OR REPLACE TRIGGER SuspendedAccount
BEFORE INSERT ON ACCOUNT
FOR EACH ROW
DECLARE
varIsProblemAccount Int;
BEGIN
SELECT COUNT(*) INTO varIsProblemAccount
FROM ACCOUNT
WHERE CUSTID = :new.custID
AND ACCSTATUS = 'Suspended';
IF (varIsProblemAccount >= 1) THEN
DBMS_OUTPUT.PUT_LINE('*************************************************');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE(' Transaction canceled. ');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE(' Refer customer to the manager immediately. ');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('**************************************************');
RETURN;
END;
ELSIF (varIsProblemAccount = 0) THEN
BEGIN
DBMS_OUTPUT.PUT_LINE('*************************************************');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE(' Transaction completed. ');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE(' Thank the customer for their business. ');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('**************************************************');
END;
END IF;
END;
對不起,我試圖更改爲0,因爲它永遠是「空」,但它仍然沒有工作
我認爲你不能在同一個表的觸發器觸發是做DML。這會引發一個「變異表」異常? – Rene