sql:

创建序列序列序列系统日志,以1乘以1开始
CREATE SEQUENCE seq_sys_log START WITH 1 INCREMENT BY 1;

oracle中创建系统日志的使用

1、sequence的基本用法:

 

[sql] view plain copy

 

  1. create sequence SEQ_ON_USER  
  2. minvalue 1  
  3. maxvalue 999999999999999999999999999  
  4. start with 1  
  5. increment by 1  
  6. nocache;    

 

说明:

 minvalue:序列最小值

 maxvalue/nomaxvalue:序列最大值/没有最大值

 start with 1:序列从1开始

 increment by 1:每次增加1

 cache/nocache:nocache不缓存。cache缓存。开启缓存,效率高,只是如果数据库宕机了,缓存丢失,会出现序列跳号情况。

 

2、查看已有sequence:

 

[sql] view plain copy

 

  1. select * from user_sequences;  

3、删除指定sequence:

 

[sql] view plain copy

 

  1. DROP SEQUENCE SEQ_ON_USER;  

4、查看指定sequence的当前值:

两种方式:

 

[sql] view plain copy

 

  1. select last_number from user_sequences wheresequence_name='SEQ_ON_USER';  

 

 

[sql] view plain copy

 

  1. select SEQ_ON_USER.nextval from sys.dual;  

        5、创建触发器使用sequence设置主键自动插入。

 

[sql] view plain copy

 

  1. create or replace trigger "SEQ_ON_USER_GENERATOR" before  
  2.   insert on databasename1.T_USER for each row  
  3.   declare  
  4.          mid number,  
  5.   begin  
  6.     select SEQ_ON_USER.nextval into mid from dual;  
  7.     :new.id:=mid;  
  8.    end  
  9.   
  10. create trigger SEQ_ON_USER_Trigger   
  11.   
  12. before insert on T_USER for each row   
  13. begin   
  14. select SEQ_ON_USER.nextval into :new.id from dual;   
  15. end SEQ_ON_USER_Trigger;   

 

        6、代码中使用sequence.nextval插入主键值。

相关文章:

  • 2022-01-13
  • 2022-01-16
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2021-05-18
  • 2021-10-12
  • 2022-02-20
猜你喜欢
  • 2021-07-20
  • 2021-10-13
  • 2021-12-06
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-10-13
相关资源
相似解决方案