ORA-04071:缺少BEFORE,AFTER或INSTEAD OF关键字错误

时间:2012-12-24 20:37:03

标签: sql oracle triggers

CREATE TRIGGER TRG_LOADMONEY
ON KIOSK
AFTER INSERT
AS
DECLARE @LOADEDCARDID INT
DECLARE @LOADEDAMOUNT INT

SELECT @LOADEDCARDID = LOADEDCARDID, @LOADEDAMOUNT = LOADEDAMOUNT FROM INSERTED
UPGRADE CARD SET CHARGE = CHARGE + @LOADEDAMOUNT
WHERE CARDID = @LOADEDCARDID

我运行此代码,但我遇到的错误是“ORA-04071:错过BEFORE,AFTER或INSTEAD OF关键字”。我有AFTER声明,我不明白这是什么问题。

1 个答案:

答案 0 :(得分:7)

您使用的语法是sql server。

试试这个:

CREATE OR REPLACE TRIGGER TRG_LOADMONEY
AFTER INSERT
ON KIOSK FOR EACH ROW
/*  
 These variables are not required because Oracle triggers can reference the table's
 columns directly using the :OLD and :NEW prefixes.   
 DECLARE 
     LOADEDCARDID PLS_INTEGER;
     LOADEDAMOUNT PLS_INTEGER;
*/
BEGIN
   UPDATE CARD 
      SET CHARGE = CHARGE + :NEW.LOADEDAMOUNT
    WHERE CARDID = :NEW.LOADEDCARDID;
END;