pl sql触发器从序列中插入值

时间:2013-11-03 21:14:30

标签: sql oracle plsql triggers

create table userdetail(
  userdetailsid number(3) not null,
  userid varchar2(5),
  firstname varchar2(15),
  lastname varchar2(15),
  email varchar2(15),
  primary key (userdetailsid)
);

create sequence Iseq
start with 1
increment by 1;

create or replace trigger userDetailInsert
before insert on userdetail
begin
  :userdetailsid:=Iseq.nextval;
end;

我得到的错误如下:

Error at line 2: PLS-00049: bad bind variable 'USERDETAILSID'

1 个答案:

答案 0 :(得分:2)

:移除:userdetailsid或与:old.结合使用:new / for each row

create or replace trigger userDetailInsert
before insert on userdetail for each row
begin
   :new.userdetailsid:=Iseq.nextval;
end;

如果您使用:,则列名称将被视为bind variable

一般说来,如果你想引用旧值或新值,请使用:old.userdetailsid resp。 :new.userdetailsid