我正在尝试设置一个触发器,这样每当更新PL_Witness表时,它会在PLAUDWIT表中记录这个,这是一个审计表。
但是,每次我尝试进行此触发器时都会遇到错误的绑定变量,而我正在尝试使用其他审计触发器。我的共同问题是什么?
感谢所有帮助!
CREATE TABLE "PL_WITNESS"
( "WITNESS_ID" NUMBER(*,0) NOT NULL ENABLE,
"WITNESS_NAME" VARCHAR2(30) NOT NULL ENABLE,
"WITNESS_ADDRESS" VARCHAR2(100),
"FK1_WITNESS_TYPE_ID" NUMBER(*,0) NOT NULL ENABLE,
CONSTRAINT "PK_WITNESS" PRIMARY KEY ("WITNESS_ID") ENABLE
)
/
ALTER TABLE "PL_WITNESS" ADD CONSTRAINT "FK1_WITNESS_WTYPE" FOREIGN KEY ("FK1_WITNESS_TYPE_ID")
REFERENCES "PL_WITNESS_TYPE" ("WITNESS_TYPE_ID") ENABLE
/
DROP TABLE PLAUDWIT
CREATE TABLE PLAUDWIT (
AUD_AWitnessID NUMBER,
AUD_AWitnessType NUMBER,
AUDIT_USER varchar2(50),
AUDIT_DATE DATE,
AUDIT_ACTION varchar2(10));
。 创建或替换TRIGGER TRG_PLAUDWIT
AFTER INSERT OR DELETE OR UPDATE ON PL_WITNESS
FOR EACH ROW
DECLARE
v_trigger_task varchar2(10);
BEGIN
IF UPDATING
THEN
v_trigger_task := 'Update';
ELSIF DELETING
THEN
v_trigger_task := 'DELETE';
ELSIF INSERTING
THEN
v_trigger_task := 'INSERT';
ELSE
v_trigger_task := NULL;
END IF;
IF v_trigger_task IN ('DELETE','UPDATE') THEN
INSERT INTO PLAUDWIT (AWitnessID, AWitnessType, AUDIT_USER, AUDIT_DATE, AUDIT_ACTION)
VALUES
(:OLD.AWitnessID, :OLD.AWitnessType, UPPER(v('APP USER')), SYSDATE, v_trigger_task);
ELSE
INSERT INTO PLAUDWIT (AWitnessID, AWitnessType, AUDIT_USER, AUDIT_DATE, AUDIT_ACTION)
VALUES
(:NEW.AWitnessID, :NEW.AWitnessType, UPPER(v('APP USER')), SYSDATE, v_trigger_task);
END IF;
END TRG_PLAUDWIT;
答案 0 :(得分:3)
您指的是绑定变量,开头是'A'
而没有下划线,例如:OLD.AWitnessID
,但您的表格列只是WITNESS_ID
。所以它们不匹配,并产生这个错误。您甚至没有WITNESS_TYPE
列。
然后在您的insert
语句中,您在审计表中的列名也是错误的。您还将变量设置为Update
,但检查UPDATE
- remmeber,对于字符串值,比较区分大小写。
这将使用您的架构进行编译:
CREATE OR REPLACE TRIGGER TRG_PLAUDWIT
AFTER INSERT OR DELETE OR UPDATE ON PL_WITNESS
FOR EACH ROW
DECLARE
v_trigger_task varchar2(10);
BEGIN
IF UPDATING THEN
v_trigger_task := 'UPDATE';
ELSIF DELETING THEN
v_trigger_task := 'DELETE';
ELSIF INSERTING THEN
v_trigger_task := 'INSERT';
ELSE
v_trigger_task := NULL;
END IF;
IF v_trigger_task IN ('DELETE','UPDATE') THEN
INSERT INTO PLAUDWIT (AUD_AWitnessID, AUD_AWitnessType, AUDIT_USER,
AUDIT_DATE, AUDIT_ACTION)
VALUES (:OLD.Witness_ID, :OLD.FK1_WITNESS_TYPE_ID, UPPER(v('APP USER')),
SYSDATE, v_trigger_task);
ELSE
INSERT INTO PLAUDWIT (AUD_AWitnessID, AUD_AWitnessType, AUDIT_USER,
AUDIT_DATE, AUDIT_ACTION)
VALUES (:NEW.Witness_ID, :NEW.FK1_WITNESS_TYPE_ID, UPPER(v('APP USER')),
SYSDATE, v_trigger_task);
END IF;
END TRG_PLAUDWIT;
/