首页 新闻 会员 周边 捐助

oracle 创建触发器是非法的 ORA-04098: trigger 'USER_TRIGGER'is invalid and failed re-v

0
悬赏园豆:5 [已解决问题] 解决于 2013-05-08 09:24

ORA-04098: ORA-04098: trigger 'USER_TRIGGER'is invalid and failed re-valid

代码:

 

create table t_user(
    user_id int primary key,
    user_name varchar(30),
    credits int,
    u_password varchar(32),
    last_visit date,
    last_ip varchar(23)
); 

 

CREATE SEQUENCE user_id_seq INCREMENT BY 1 START WITH 1;

 

CREATE TRIGGER TRG_USER
BEFORE INSERT ON T_USER
FOR EACH ROW
  BEGIN
    INSERT INTO T_USER(USER_ID)
    VALUES(USER_ID_SEQ.NEXTVAL);
    END;
    INSERT INTO T_USER(USER_NAME,U_PASSWORD) VALUES('admin','123456');

随风轻扬的主页 随风轻扬 | 初学一级 | 园豆:197
提问于:2012-10-23 09:44
< >
分享
最佳答案
0

看样子是想实现自增列吧!

我把你的触发器改了一下,你的那种写法会递归的!

SQL如下:

CREATE TABLE T_USER(
     USER_ID INT PRIMARY KEY,
     USER_NAME VARCHAR(30),
     CREDITS INT,
     U_PASSWORD VARCHAR(32),
     LAST_VISIT DATE,
     LAST_IP VARCHAR(23)
 ); 
  
 CREATE SEQUENCE USER_ID_SEQ INCREMENT BY 1 START WITH 1;
  
 CREATE OR REPLACE TRIGGER TRG_USER
   BEFORE INSERT ON T_USER  
   FOR EACH ROW
 BEGIN
   SELECT USER_ID_SEQ.NEXTVAL INTO :NEW.USER_ID FROM DUAL;
 END TR_FCBOOK;
 
 INSERT INTO T_USER(USER_NAME,U_PASSWORD) VALUES('ADMIN','123456');
         
 --DROP TABLE T_USER;
 --DROP SEQUENCE USER_ID_SEQ;
 --DROP TRIGGER TRG_USER;
收获园豆:5
方外老和尚 | 菜鸟二级 |园豆:361 | 2012-10-26 17:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册