SQL> create table scott.logon( 2 id number(4) not null primary key, 3 name varchar(10), 4 password varchar(20));
Table created
SQL> create sequence logon_sequence 2 increment by 1 3 start with 1 4 nomaxvalue 5 nocycle 6 cache 10;
Sequence created
SQL> create trigger logon_tg before insert on scott.logon 2 for each row 3 begin 4 select logon_sequence.nextval into:new.id from dual; 5 end; 6 commit; 7 触发器中不能commit 除非使用自治事务 问题时你这触发器中的查询语句在执行时输出到哪儿呢?控制台>
做个标记。 这里的触发器应该用after吧,但会提示ORA-04084:cannot change NEW values for this trigger type。期待高手解决 我测试了一下,除了commit; 没有问题 insert into logon(name) values('aaa'); insert into logon(name) values('aaa'); insert into logon(name) values('bbb');
select * from logon /
ID NAME PASSWORD ----- ---------- -------------------- 1 aaa 2 aaa 3 bbb