Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

SQL Scripts & Samples

Posted Mar 23, 2009

Panic SEQuences

By DatabaseJournal.com Staff



>>Script Language and Platform: Oracle
This script will generate all sequences in the database.
We run this script on weekly base.

Author: Yakov Shlafman


set serveroutput off
set lines 200 trimspool on pages 1000
set pagesize 0
set recsep off
col "--CMD--" for a60
set recsep off trimspool on

BREAK ON OWNER;
BREAK ON SEQUENCE_NAME;

SELECT 'CREATE SEQUENCE'||CHR(10)||CHR(9)||CHR(9)
||SEQUENCE_OWNER||'.'||SEQUENCE_NAME||CHR(10)||CHR(9)||CHR(9)
||'INCREMENT BY '||INCREMENT_BY||CHR(10)||CHR(9)||CHR(9)
||DECODE(MIN_VALUE
, -99999999999999999999999999,'NOMINVALUE'||CHR(10)||CHR(9)||CHR(9),
'MINVALUE '||MIN_VALUE||CHR(10)||CHR(9)||CHR(9))
||DECODE(MAX_VALUE
, 999999999999999999999999999,'NOMAXVALUE'||CHR(10)||CHR(9)||CHR(9),
'MAXVALUE '||MAX_VALUE||CHR(10)||CHR(9)||CHR(9))
||'START WITH '||LAST_NUMBER||CHR(10)||CHR(9)||CHR(9)
||DECODE(CYCLE_FLAG
, 'Y', 'CYCLE'||CHR(10)||CHR(9)||CHR(9)
, 'N', 'NOCYCLE'||CHR(10)||CHR(9)||CHR(9))
||DECODE(CACHE_SIZE
, 0 , 'NOCACHE '||CHR(10)||CHR(9)||CHR(9)
, 'CACHE '||CACHE_SIZE||CHR(10)||CHR(9)||CHR(9))
||DECODE(ORDER_FLAG, 'N', 'NOORDER ','ORDER ')||CHR(10)||';'
--
"--CMD--"
FROM
ALL_SEQUENCES
WHERE
SEQUENCE_OWNER NOT IN ('SYS', 'SYSTEM')
;


---------------------------------
-- Output RESULTS (Sample)
---------------------------------
CREATE SEQUENCE
KOSHKA.N1
INCREMENT BY 50
MINVALUE 1
MAXVALUE 30000
START WITH 2510
NOCYCLE
CACHE 30
ORDER
;

CREATE SEQUENCE
NORTPA.SEQ1
INCREMENT BY 1
MINVALUE 1
NOMAXVALUE
START WITH 100
NOCYCLE
NOCACHE
ORDER
;
CREATE SEQUENCE
NORTPA.SEQ12
INCREMENT BY 1
MINVALUE 1
MAXVALUE 4294967295
START WITH 1
NOCYCLE
NOCACHE
NOORDER
;
CREATE SEQUENCE
TRIKTR.SEQ15
INCREMENT BY 1
MINVALUE -2147483647
MAXVALUE 2147483647
START WITH 1
NOCYCLE
NOCACHE
NOORDER
;
CREATE SEQUENCE
TRIKTR.TEST_I1D225
INCREMENT BY 50
MINVALUE 1
MAXVALUE 30000
START WITH 400
NOCYCLE
NOCACHE
ORDER
;
CREATE SEQUENCE
WOFTAK.TEST_ID232
INCREMENT BY 50
MINVALUE 1
MAXVALUE 30000
START WITH 100
NOCYCLE
NOCACHE
ORDER
;
CREATE SEQUENCE
WOFTAK.TEST_ID71232
INCREMENT BY 50
MINVALUE 1
MAXVALUE 30000
START WITH 100
NOCYCLE
CACHE 107
ORDER
;


Disclaimer: We hope that the information on these script pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, or fitness for a particular purpose... Disclaimer Continued


Back to Database Journal Home



SQL Scripts & Samples Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
SQL Scripts & Samples Forum
Topic By Replies Updated
sql help!! add 1 August 22nd, 11:58 AM
How To Combine These 2 Queries into 1 Query ? tarek_land 1 June 7th, 08:37 AM
solving query svibuk 1 February 3rd, 06:08 AM
converting from a character string to uniqueidentifier saturnius 4 January 4th, 05:56 AM


















Thanks for your registration, follow us on our social networks to keep up-to-date