SQL语句忽略Oracle触发器中缺少的表达式

时间:2015-09-22 09:34:36

标签: oracle triggers sql-insert

我正在编写下面的触发器,我在尝试插入此字段FIELD_OLD_VALUE,FIELD_NEW_VALUE的值时收到错误。我必须根据Select查询插入此字段的值,但我得到的错误为SQL Statement Ignored ORA-000936 missing expression in Oracle trigger。我不想在字段FIELD_OLD_VALUE,FIELD_NEW_VALUE中使用变量,因为我在此问题中仅为ENV_ID字段编写了insert语句,并且我在此触发器中添加了许多其他字段。因此很难对每个领域进行变量和维护。

create or replace TRIGGER RATOR_MONITORING_CONFIGURATION."TRG_TRK_KPI_DEFINITION" AFTER UPDATE ON RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION
  FOR EACH ROW

BEGIN
  --NEU
  IF NOT  :old.ENV_ID=:new.ENV_ID THEN
    INSERT INTO RATOR_MONITORING_CONFIGURATION.FIELD_TRACKING  (FIELD_TRACKING_ID,TABLE_NAME,TABLE_ID, FIELD_NAME,FIELD_OLD_VALUE,FIELD_NEW_VALUE,USER_ID, TIMESTAMP)
    VALUES (FIELD_TRACKING_SEQ.NEXTVAL,'KPI_DEFINITION',:new.KPI_DEF_ID,'Environment',to_char(Select NAME FROM ENVIRONMENT WHERE ENV_ID =:old.ENV_ID),to_char(Select NAME FROM ENVIRONMENT WHERE ENV_ID =:new.ENV_ID),:new.LAST_UPDATED_BY,:new.LAST_UPDATED_DATE );
  END IF;
END;

1 个答案:

答案 0 :(得分:2)

如果您使用子查询作为参数,则需要将它们包含在额外的括号中:

to_char((Select NAME FROM ENVIRONMENT WHERE ENV_ID =:old.ENV_ID))