我正在尝试将审核添加到Oracle数据库中的表中,但我一直收到PLS-00049错误。 这是我的剧本:
CREATE OR REPLACE TRIGGER gfmdev.audit_feature_performance
BEFORE INSERT OR UPDATE
ON gfmdev.feature_performance
FOR EACH ROW
DECLARE
osuser VARCHAR2(8);
BEGIN
--
-- get who is making the DML change from the session
--
osuser := session_info.osuser;
--
IF (NOT (dbms_snapshot.i_am_a_refresh)
AND dbms_reputil.replication_is_on) THEN
IF NOT dbms_reputil.from_remote THEN
IF INSERTING THEN
:new.created_by := osuser;
:new.creation_date := sysdate;
:new.last_updated_by := osuser;
:new.last_updated_date := sysdate;
END IF;
--
IF UPDATING THEN
:new.last_updated_by := osuser;
:new.last_updated_date := sysdate;
END IF;
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
-- raise error if we cannot set auditing fields
raise_application_error(-20505, 'audit_feature_performance Failed. Rolling Back.' || SQLERRM);
END;
抛出的错误是:
PLS-00049: bad bind variable 'NEW.LAST_UPDATED_BY'
PLS-00049: bad bind variable 'NEW.LAST_UPDATED_DATE'
PLS-00049: bad bind variable 'NEW.LAST_UPDATED_BY'
PLS-00049: bad bind variable 'NEW.LAST_UPDATED_BY'
PLS-00049: bad bind variable 'NEW.LAST_UPDATED_DATE'
我无法弄清楚为什么会这样。在这方面的任何帮助都非常感谢。
答案 0 :(得分:0)
尝试:
created_by:= osuser; :new.creation_date:= sysdate; :new.last_updated_by:= osuser; :new.last_updated_date
alter table gfmdev.feature_performance add (
created_by varchar2(100),
creation_date date,
LAST_UPDATED_BY varchar2(100),
LAST_UPDATED_DATE date
)
/
然后执行create trigger命令,或重新编译它。
答案 1 :(得分:0)
尝试使用REFERENCING OLD AS OLD NEW AS NEW
。
CREATE OR REPLACE TRIGGER gfmdev.audit_feature_performance
BEFORE INSERT OR UPDATE ON gfmdev.feature_performance
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE