小编典典

PLS-00049错误的绑定变量

sql

我正在尝试设置一个触发器,以便每当更新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));

。创建或替换触发器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;


阅读 209

收藏
2021-04-15

共1个答案

小编典典

您指的'A'是开头是且没有下划线的绑定变量,例如:OLD.AWitnessID,但是表列是just
WITNESS_ID。因此它们不匹配,并产生此错误。您甚至没有WITNESS_TYPE专栏。

然后,在您的insert语句中,审计表中的列名也将错误。您还可以将变量设置为,Update但要检查UPDATE-注意:对于字符串值,比较是区分大小写的。

这将与您的架构一起编译:

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;
/
2021-04-15