【Oracle】生成序列脚本

今天在移植一个项目的的数据库时,要移动所有的序列,下面就是一个如何生成序列脚本的语句

方法一

SELECT ' CREATE SEQUENCE '||SEQUENCE_NAME|| ' INCREMENT BY '||   
        INCREMENT_BY ||' START WITH '||LAST_NUMBER||' MAXVALUE '||   
        MAX_VALUE  ||'   CACHE '||CACHE_SIZE||' ORDER NOCYCLE ;'  
FROM user_SEQUENCES;

结果类似

CREATE SEQUENCE ARTCOMMENT_SEQ INCREMENT BY 1 START WITH 341 MAXVALUE 999999999999999999999999999   CACHE 20 ORDER NOCYCLE ;

CREATE SEQUENCE ARTICLEVISTCECOLLECT_SEQ INCREMENT BY 1 START WITH 1 MAXVALUE 999999999999999999999999999   CACHE 20 ORDER NOCYCLE ;

CREATE SEQUENCE ARTICLEVISTTEMP_SEQ INCREMENT BY 1 START WITH 82989 MAXVALUE 999999999999999999999999999   CACHE 20 ORDER NOCYCLE ;

CREATE SEQUENCE ARTICLEVIST_SEQ INCREMENT BY 1 START WITH 1675 MAXVALUE 999999999999999999999999999   CACHE 20 ORDER NOCYCLE ;

CREATE SEQUENCE ARTICLE_SEQ INCREMENT BY 1 START WITH 1908 MAXVALUE 999999999999999999999999999   CACHE 20 ORDER NOCYCLE ;

20131216154245281.png

方法二

select dbms_metadata.get_ddl('SEQUENCE',u.object_name) from user_objects u where object_type='SEQUENCE'

结果类似

CREATE SEQUENCE  "MO_VO"."ARTCOMMENT_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 341 CACHE 20 ORDER  NOCYCLE ;

CREATE SEQUENCE  "MO_VO"."ARTICLEVISTCECOLLECT_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 ORDER  NOCYCLE ;

CREATE SEQUENCE  "MO_VO"."ARTICLEVISTTEMP_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 82989 CACHE 20 ORDER  NOCYCLE ;

CREATE SEQUENCE  "MO_VO"."ARTICLEVIST_SEQ"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1675 CACHE 20 ORDER  NOCYCLE ;

 

----end-----


未经允许请勿转载:程序喵 » 【Oracle】生成序列脚本

点  赞 (1) 打  赏
分享到: