创建一个表aaa,自增字段为id,为其创建一个序列aaa_i,然后是一个触发器,请问哪里有问题,表和序列都没问题,触发器执行的时候说是
警告:创建的触发器带有编译错误
再insert数据的时候报错:
ORA-04098: trigger 'SYSTEM.AAA_ID' is invalid and failed re-validation大家帮忙看看哪一步出问题了?谢谢了。create table aaa
(
id int not null,
name varchar2(50),
primary key (id)
);create sequence aaa_i increment by 1 start with 1;create or replace trigger aaa_id
before insert on aaa
for each row
begin
if :new.id is NULL or :new.id=0 then
select aaa_i.nextval into :new.id from dual;
end if;
end aaa_id;
/insert into aaa values(NULL, 'liming');
警告:创建的触发器带有编译错误
再insert数据的时候报错:
ORA-04098: trigger 'SYSTEM.AAA_ID' is invalid and failed re-validation大家帮忙看看哪一步出问题了?谢谢了。create table aaa
(
id int not null,
name varchar2(50),
primary key (id)
);create sequence aaa_i increment by 1 start with 1;create or replace trigger aaa_id
before insert on aaa
for each row
begin
if :new.id is NULL or :new.id=0 then
select aaa_i.nextval into :new.id from dual;
end if;
end aaa_id;
/insert into aaa values(NULL, 'liming');
--try it
--触发器
create or replace trigger aaa_id
before insert on aaa
for each row
begin
select aaa_i.nextval into :new.id from dual;end;
--插入
insert into aaa(name) values('liming');
insert into aaa(name) values('liming');--对的,应该是这样子来操作
(
id int not null,
name varchar2(50),
primary key (id)
);create sequence aaa_i
minvalue 1
maxvalue 99999999999
start with 1
increment by 1 ;insert into aaa values(aaa_i.nextval, 'liming');
就是为了可以不写那一列,或者直接写个空就行了,而不用非要写一个nextval才用的触发器不过还是感谢。。
同感,lz既然建了sequence直接用insert into aaa values(aaa_i.nextval, 'liming'); 就ok了
,没必要再写个触发器啊
前面有一些特殊字符,把它们删除就行了
(
id int not null,
name varchar2(50),
primary key (id)
);create sequence aaa_i increment by 1 start with 1;create or replace trigger aaa_id
before insert on aaa
for each rowbegin
select aaa_i.nextval into :new.id from dual;
end;
insert into aaa(name) values('liming');