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');
看样子是想实现自增列吧!
我把你的触发器改了一下,你的那种写法会递归的!
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;