无法绑定(错误绑定)Oracle触发器中的值

时间:2019-04-29 11:00:22

标签: oracle plsql database-trigger

我正在创建触发器,在其中需要在单独的表中为该表创建日志。触发器在插入或更新时运行,并按列名和值添加值,以下为脚本;

这给我一个无法绑定值的错误

CREATE OR REPLACE TRIGGER MY_TABLE_TRGGER
   AFTER INSERT OR UPDATE
   ON MY_TABLE
   REFERENCING NEW AS NEW OLD AS OLD
   FOR EACH ROW
BEGIN
   FOR R IN (SELECT COLUMN_NAME, TABLE_NAME
               FROM USER_TAB_COLUMNS
              WHERE TABLE_NAME = 'MY_TABLE')
   LOOP
      IF UPDATING (R.COLUMN_NAME)
      THEN
         INSERT INTO MY_LOGS_TABLE (COLUMN_NAME,
                                    CREATED_BY,
                                    CREATED_ON,
                                    CURRENT_COL_VALUE,
                                    OLD_COL_VALUE,
                                    TABLE_NAME,
                                    UPDATED_BY,
                                    UPDATED_ON)
              VALUES ('' || R.COLUMN_NAME || '' , /* COLUMN name as string */,
                      :NEW.CREATED_BY ,
                      :NEW.CREATED_ON,
                      :NEW.R.COLUMN_NAME /* UNABLE TO BIND THIS VALUE */,
        :OLD.R.COLUMN_NAME/* UNABLE TO BIND THIS VALUE */,
        ''|| R.TABLE_NAME ||'' ,/* TABLE name as string */
        :NEW.UPDATED_BY,
        :NEW.UPDATED_ON );
       END IF;
    END LOOP;
END MY_TABLE_TRGGER;

0 个答案:

没有答案