oracle自增主键

http://www.cnblogs.com/yomho/p/3714574.html

//创建序列
 SQL>create sequence log_seq
 increment by 1
 start with 1
 nomaxvalue
 order
 nocycle    
 cache 10;​

//创建触发器
 SQL>create or replace trigger log_seq_trig
 before insert on OPERATELOG
 for each row
 begin
 select log_seq.nextval into :new.log_id from dual;
 end log_seq_trig;
 /

//查看当前用户的所有序列    
select SEQUENCE_OWNER,SEQUENCE_NAME from dba_sequences where sequence_owner='用户名'; 
//查询序列的下一个值(查询一次就增长一次)
select LOG_SEQ.NEXTVAL FROM DUAL;

//不删除序列的情况下重置序列数
select  JBR_REPORT_SEQ.nextval from dual;
alter sequence JBR_REPORT_SEQ increment by -8;
select JBR_REPORT_SEQ.nextval from dual;
alter sequence JBR_REPORT_SEQ increment by 1;

//查询某个表所拥有的触发器
select trigger_name from all_triggers where table_name='XXX';  
//查询某个触发器的详细信息
select text from all_source where type='TRIGGER' AND name='TR_XXX'; 
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容