我是甲骨文的新人。我正在尝试使用自动递增的主键功能在oracle 10g中创建一个表。而我正在做这个创造触发器。我创建了2个表1.SERVLET_JSP_REGISTRATION和2.BOOKS。
Sql for SERVLET_JSP_REGISTRATION
CREATE TABLE "SERVLET_JSP_REGISTRATION"
("FIRSTNAME" VARCHAR2(4000),
"LASTNAME" VARCHAR2(4000),
"EMAIL" VARCHAR2(4000),
"PASSWORD" VARCHAR2(4000),
"ADDRESS" VARCHAR2(4000),
"CITY" NUMBER,
"SKILLS" VARCHAR2(4000),
"LOCATION" VARCHAR2(4000),
"PHONE" VARCHAR2(4000),
"MARITALSTATUS" NUMBER,
"ID" NUMBER,
CONSTRAINT "MY_PK" PRIMARY KEY ("ID") ENABLE
)
/
CREATE OR REPLACE TRIGGER "BI_SERVLET_JSP_REGISTRATION" before insert on SERVLET_JSP_REGISTRATION
for each row
begin
if :NEW.ID is null then
select SERVLET_JSP_REGISTRATION_SEQ.nextval into :NEW.ID from dual;
end if;
end;
/
ALTER TRIGGER "BI_SERVLET_JSP_REGISTRATION" ENABLE
/
SQL for Books
CREATE TABLE "BOOKS"
( "ID" NUMBER,
"TITLE" VARCHAR2(4000),
"AUTHOR" VARCHAR2(4000),
"DESCRIPTION" VARCHAR2(4000),
"PRICE" NUMBER,
"PUBLISHED_ON" DATE,
"STATUS" NUMBER,
CONSTRAINT "BOOKS_PK" PRIMARY KEY ("ID") ENABLE
)
/
CREATE OR REPLACE TRIGGER "BI_BOOKS" before insert on BOOKS
for each row
begin
if :NEW.ID is null then
select BOOK_SEQ.nextval into :NEW.ID from dual;
end if;
end;
/
ALTER TRIGGER "BI_BOOKS" ENABLE;
/
ALTER TRIGGER "BI_BOOKS" ENABLE
/
但是当我尝试在两个表上插入一行时,SERVLET_JSP_REGISTRATION就可以了,但是在BOOKS的情况下,它显示错误" 错误ORA-04098:触发&#39 ; SYSTEM.BI_BOOKS'无效且重新验证失败" ---你能告诉我问题在哪里以及如何解决?提前谢谢。