PLS-00049:绑定变量'NEW.NEW_SKILL_DESC'错误

时间:2019-01-10 11:24:59

标签: oracle triggers bind

当我运行触发器时,PLS-00049:错误的绑定变量'NEW.NEW_SKILL_DESC'出现了问题。在以下位置出现问题:新建部分。这是我第一次审核数据库查询。

CREATE OR REPLACE TRIGGER lds_skill_trig
  BEFORE INSERT OR DELETE OR UPDATE ON LDS_SKILL
  FOR EACH ROW
ENABLE
DECLARE
  v_user VARCHAR2(30);
  v_date VARCHAR2(30);
BEGIN
  SELECT user, TO_CHAR(sysdate, 'DD/M0N/YYYY HH24:MI:SS') 
  INTO v_user, v_date FROM dual;
    IF INSERTING THEN
      INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc,user_name, 
     entry_date, operation)
    VALUES(:NEW.new_skill_desc, NULL, v_user, v_date, 'Insert');
  ELSIF DELETING THEN
    INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc, user_name, 
     entry_date, operation)
    VALUES(NULL, :OLD.new_skill_desc, v_user, v_date, 'Delete');
  ELSIF UPDATING THEN
    INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc, user_name, 
      entry_date, operation)
    VALUES(:NEW.new_skill_desc, :OLD.new_skill_desc, v_user, v_date,'update');
  END IF;
END;

这是db_lds_skill的表,我要保存审计记录。

CREATE TABLE DB_LDS_SKILL
(NEW_SKILL_DESC VARCHAR2(30), 
OLD_SKILL_DESC VARCHAR2(30), 
USER_NAME VARCHAR2(30), 
ENTRY_DATE VARCHAR2(30), 
OPERATION VARCHAR2(30)
);

enter image description here

1 个答案:

答案 0 :(得分:1)

似乎您在:NEW.new_skill_desc中添加了错误的列名,在:new.中,您必须指定表LDS_SKILL表的列,而不是db_lds_skill的列

下面是我在本地创建的,并且工作正常,请注意,我将to_date替换为to_char,并将M0N替换为MON

drop table db_lds_skill
/
create table db_lds_skill 
(new_skill_desc varchar2(100) null,
 old_skill_desc varchar2(100) null,
 user_name varchar2(100) null, 
 entry_date varchar2(100),
 operation varchar2(100) null
)
/
drop table LDS_SKILL
/
create table LDS_SKILL 
(new_skill_desc varchar2(100) null,
 old_skill_desc varchar2(100) null,
 user_name varchar2(100) null, 
 entry_date varchar2(100) nulll,
 operation varchar2(100) null
)
/
CREATE OR REPLACE TRIGGER lds_skill_trig
  BEFORE INSERT OR DELETE OR UPDATE ON LDS_SKILL
  FOR EACH ROW
ENABLE
DECLARE
  v_user VARCHAR2(30);
  v_date VARCHAR2(30);
BEGIN
  SELECT user, TO_CHAR(sysdate, 'DD/MON/YYYY HH24:MI:SS') 
  INTO v_user, v_date FROM dual;
    IF INSERTING THEN
      INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc,user_name, 
     entry_date, operation)
    VALUES(:NEW.new_skill_desc, NULL, v_user, v_date, 'Insert');
  ELSIF DELETING THEN
    INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc, user_name, 
     entry_date, operation)
    VALUES(NULL, :OLD.new_skill_desc, v_user, v_date, 'Delete');
  ELSIF UPDATING THEN
    INSERT INTO db_lds_skill(new_skill_desc, old_skill_desc, user_name, 
      entry_date, operation)
    VALUES(:NEW.new_skill_desc, :OLD.new_skill_desc, v_user, v_date,'update');
  END IF;
END;
/
insert into LDS_SKILL (new_skill_desc) values('pp')
/
commit
/