写了一个自增列的触发器、序列,可是插入的时候老说触发器失败。请各位大侠帮忙看看。。感激不尽
/*创建表*/
create table USERS
(
  ID       NUMBER not null,
  NAME     VARCHAR2(50) not null,
  PASSWORD VARCHAR2(50) not null
)/*创建序列*/
create  sequence s_id increment by 1 start with 1 nomaxvalue nocycle; 
/*创建触发器*/ 
create or replace trigger USERS_TRIGGER 
  before insert on USERS 
  referencing old as old_value new as new_value 
  for each row   WHEN (new_value.id is null)
begin   
Select  s_id.nextval into: new_value.id from dual;
end;   
/*插入数据*/
INSERT INTO USERS(NAME,PASSWORD) VALUES('AA','BB')
错误:trigger 'de_test.user_trigger' is invalid and failed re-validation另外from dual是什么意思呢?网上查了很多例子都有这个。。

解决方案 »

  1.   

    create  sequence s_id increment by 1 start with 1 nomaxvalue nocycle; 
    /*创建触发器*/ 
    create or replace trigger USERS_TRIGGER 
      before insert on USERS 
      for each row  WHEN (new.id is null) 
    begin  
    :new.id:= s_id.nextval; 
    end;  
      

  2.   

    dual是一个虚拟表,用来查那些不属于实际表里的内容
      

  3.   

    你的错误在于:------------------
    begin  
    Select  s_id.nextval into: new_value.id from dual; 
    end;
    -------------------
    应该改为:
    begin  
    Select  s_id.nextval into :new_value.id from dual; 
    end;