oracle实现id自增长

  1. drop table book;   
  2. --创建表      
  3. create table book(       
  4.    bookId varchar2(4) primary key,   
  5.    name varchar2(20)         
  6. );   
  7. --创建序列      
  8. create sequence book_seq start with 1 increment by 1;    
  9.   
  10. --创建触发器      
  11. create or replace trigger book_trigger       
  12. before insert on book       
  13. for each row       
  14. begin       
  15. select book_seq.nextval into :new.bookId from dual;      
  16. end ;   
  17. --添加数据      
  18. insert into book(name)  values ('cc');    
  19. insert into book(name)  values ('dd');   
  20.   
  21. commit;  

猜你喜欢

转载自ccyuankai.iteye.com/blog/2094707