使用触发器时,Oracle SQL ORA-24344成功,出现编译错误

时间:2018-10-18 02:23:04

标签: oracle triggers database-trigger

请帮助解决以下代码吗?

  

遇到错误代码ORA-24344

CREATE OR REPLACE TRIGGER Table_TRG
AFTER INSERT OR UPDATE
ON Table_A
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW 
BEGIN 
    IF (:NEW.EQP_ID <> :OLD.EQP_ID AND :NEW.OP_ID <> :OLD.OP_ID)THEN
        INSERT INTO Table_B
                (EQP_ID, OP_ID, SV_RECORD, UPDATE_TIME)
                VALUES
                (:NEW.EQP_ID, :NEW.OP_ID, :NEW.SV_RECORD, :NEW.UPDATE_TIME);
        ELSE
                UPDATE INTO Table_B
                SET :OLD.SV_RECORD = :NEW.SV_RECORD,
                :OLD.EQP_ID = :NEW.EQP_ID,
                :OLD.OP_ID = :NEW.OP_ID,
                :OLD.UPDATE_TIME = :NEW.SYSTIMESTAMP;
    END IF;
END;

谢谢。

1 个答案:

答案 0 :(得分:2)

您的更新语句中有语法错误。此外,REFERENCING NEW AS NEW OLD AS OLD是不必要的。

在您的更新语句中,op_ideqp_id是否应该放在where clause中而不是SET中?

CREATE OR REPLACE TRIGGER table_trg AFTER
     INSERT OR UPDATE ON table_a
     FOR EACH ROW
        BEGIN 
IF (:new.eqp_id <>:old.eqp_id AND :new.op_id <>:old.op_id ) THEN
     INSERT INTO table_b (
          eqp_id,
          op_id,
          sv_record,
          update_time
     ) VALUES (
          :new.eqp_id,
          :new.op_id,
          :new.sv_record,
          :new.update_time
     );
ELSE 
 UPDATE table_b
   SET sv_record = :new.sv_record,
    update_time  = systimestamp
 WHERE eqp_id    = :new.eqp_id   --change the columns in set and where appropriately.
   AND op_id     = :new.op_id,
     END IF;
end;
/