2
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 声明,我不明白问题出在哪里。

4

1 回答 1

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;
于 2012-12-24T20:59:11.340 回答