create table book(
bookId varchar2(4) primary key,
name varchar2(20)
);
--创建序列
create sequence book_seq start with 1 increment by 1
NOMAXvalue
NOCYCLE
NOCACHE;
--创建触发器
create or replace trigger book_trigger
before insert on book
for each row
begin
select book_seq.nextval into :new.bookId from dual;
end ;
--添加数据
insert into book(name) values ('cc');
insert into book(name) values ('dd');
commit;
select * from book;
注意 :new.bookId
要为book表中的id的名称 . :new
称之为伪记录变量, 记录着将要插入的变量值. 结果如图