Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: RE: Export Sequences from a database
This message is in MIME 1.0 Format
--===========_<mailstart.9/29/00.27866.13. gunawan.yuwono_at_webbox.com>=====_
Content-Type: text/plain
If it's not too late, here is a script that I wrote a while ago. It's pretty much the same with Ray's script. I also attached the file.
ACCEPT v_seq_owner PROMPT 'Enter Existing Sequence Owner: ' ACCEPT v_new_owner PROMPT 'Enter New Sequence Owner: ' ACCEPT v_drop_seq PROMPT 'Include Drop Sequence, Y or N: '
SPOOL create_seq.sql
DECLARE
v_max_value VARCHAR2(20); v_cycle VARCHAR2(20); v_order VARCHAR2(20); v_cache VARCHAR2(20); v_priv VARCHAR2(20); v_grantee VARCHAR2(20); v_count NUMBER; CURSOR C_SEQ IS SELECT * FROM dba_sequences WHERE sequence_owner='&&v_seq_owner';
BEGIN
FOR seq IN C_SEQ LOOP
SELECT DECODE(SIGN((seq.max_value/2147483647)-1), 1, ' NOMAXVALUE', ' MAXVALUE ' || to_char(seq.max_value)) INTO v_max_value FROMDUAL; SELECT DECODE(seq.cycle_flag, 'Y', ' CYCLE', ' NOCYCLE') INTO v_cycle FROM DUAL;
SELECT DECODE(seq.order_flag, 'Y', ' ORDER',' NOORDER') INTO v_order FROM DUAL;
SELECT DECODE(seq.cache_size, 0 , ' NOCACHE', ' CACHE ' || to_char(seq.cache_size)) INTO v_cache FROM DUAL; DBMS_OUTPUT.PUT_LINE('CREATE SEQUENCE &&v_new_owner' || '.' || seq.sequence_name); DBMS_OUTPUT.PUT_LINE(' START WITH ' || to_char(seq.min_value)); DBMS_OUTPUT.PUT_LINE(' INCREMENT BY ' || to_char(seq.increment_by)); DBMS_OUTPUT.PUT_LINE(' MINVALUE ' || to_char(seq.min_value)); DBMS_OUTPUT.PUT_LINE(v_max_value); DBMS_OUTPUT.PUT_LINE(v_cycle); DBMS_OUTPUT.PUT_LINE(v_order); DBMS_OUTPUT.PUT_LINE(v_cache || ';'); DBMS_OUTPUT.PUT_LINE('--');and privilege='SELECT';
-- GRANT Privileges
SELECT count(*) INTO v_count FROM dba_tab_privs WHERE table_name=seq.sequence_name AND owner='&&v_seq_owner'
IF v_count = 1 THEN SELECT privilege, grantee INTO v_priv, v_grantee FROM dba_tab_privs WHERE table_name=seq.sequence_name AND owner='&&v_seq_owner' and privilege='SELECT'; DBMS_OUTPUT.PUT_LINE('GRANT ' || v_priv || ' ON &&v_new_owner' || '.' || seq.sequence_name || ' TO ' || v_grantee || ';'); END IF; SELECT count(*) INTO v_count FROM dba_tab_privs WHERE table_name=seq.sequence_name AND owner='&&v_seq_owner'and privilege='ALTER';
IF v_count = 1 THEN SELECT privilege, grantee INTO v_priv, v_grantee FROM dba_tab_privs WHERE table_name=seq.sequence_name AND owner='&&v_seq_owner' and privilege='ALTER'; DBMS_OUTPUT.PUT_LINE('GRANT ' || v_priv || ' ON &&v_new_owner' || '.' || seq.sequence_name || ' TO ' || v_grantee || ';'); END IF; DBMS_OUTPUT.PUT_LINE('--');
END LOOP;
END;
/
SPOOL OFF
SET VERIFY ON
SET HEADING ON
SET FEEDBACK ON
SET ECHO ON
HTP.
Gunawan Yuwono
Oracle DBA
Kansas City, MO
>--- Original Message --- >From: Mosy Lo <mlo_at_JCICorp.com> >To: Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com> >Date: 9/28/00 9:40:21 PM >
>Thanks very very much for all your time. I got the sequences import to the
>new db with Raj's script. > >-----Original Message----- >Sent: Thursday, September 28, 2000 11:06 AM >To: Multiple recipients of list ORACLE-L > > >Import Sequences with current value ... > >SELECT 'DROP SEQUENCE ' || SEQUENCE_NAME || ' ;' >from ALL_SEQUENCES >WHERE SEQUENCE_OWNER = <owner_name> >UNION ALL >select 'CREATE SEQUENCE ' || SEQUENCE_NAME || >' INCREMENT BY ' || INCREMENT_BY || >' START WITH ' || to_char(LAST_NUMBER+1) || >' MINVALUE ' || to_char(MIN_VALUE) || >Decode(LENGTH(TO_CHAR(MAX_VALUE)), 27, '', ' MAXVALUE ' || >TO_CHAR(MAX_VALUE) ) || >Decode(CYCLE_FLAG, 'N', ' NOCYCLE', 'Y', ' CYCLE' ) || >Decode(CACHE_SIZE, 0, ' NOCACHE', ' CACHE ' || TO_CHAR(CACHE_SIZE)) ||
>Decode(ORDER_FLAG, 'N', ' NOORDER', 'Y', ' ORDER' ) || ';' >from ALL_SEQUENCES >where SEQUENCE_OWNER = <owner_name> > > >Import Sequences with start value as 1 >SELECT 'DROP SEQUENCE ' || SEQUENCE_NAME || ' ;' >from ALL_SEQUENCES >WHERE SEQUENCE_OWNER = <owner_name> >UNION ALL >select 'CREATE SEQUENCE ' || SEQUENCE_NAME || >' INCREMENT BY ' || INCREMENT_BY || >' START WITH 1' || >Decode(LENGTH(TO_CHAR(MAX_VALUE)), 27, '', ' MAXVALUE ' || >TO_CHAR(MAX_VALUE) ) || >Decode(CYCLE_FLAG, 'N', ' NOCYCLE', 'Y', ' CYCLE' ) || >Decode(CACHE_SIZE, 0, ' NOCACHE', ' CACHE ' || TO_CHAR(CACHE_SIZE)) ||
>Decode(ORDER_FLAG, 'N', ' NOORDER', 'Y', ' ORDER' ) || ';' >from ALL_SEQUENCES >where SEQUENCE_OWNER = <owner_name> > >HTH >Raj >______________________________________________________ >Rajendra Jamadagni MIS, ESPN Inc. >Rajendra dot Jamadagni at ESPN dot com >QOTD: Any clod can have facts, but having an opinion is an art!
> > > >This e-mail message is confidential, intended only for the named >recipient(s) above and may contain information that is privileged,attorney
>from your computer, Thank you. > >-- >Please see the official ORACLE-L FAQ: http://www.orafaq.com >-- >Author: Jamadagni, Rajendra > INET: rajendra.jamadagni_at_espn.com > >Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 >San Diego, California -- Public Internet access / MailingLists
>-------------------------------------------------------------------->To REMOVE yourself from this mailing list, send an E-Mail message >to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
>also send the HELP command for other information (like subscribing). >-- >Please see the official ORACLE-L FAQ: http://www.orafaq.com >-- >Author: Mosy Lo > INET: mlo_at_JCICorp.com > >Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 >San Diego, California -- Public Internet access / MailingLists
>-------------------------------------------------------------------->To REMOVE yourself from this mailing list, send an E-Mail message >to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
>also send the HELP command for other information (like subscribing). > > ----------------
--===========_<mailstart.9/29/00.27866.13. gunawan.yuwono_at_webbox.com>=====_
Content-Type: application/octet-stream; name="create_sequence.sql" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="create_sequence.sql"
U0VUIEVDSE8gT0ZGIA0KU0VUIFZFUklGWSBPRkYgDQpTRVQgSEVBRElORyBPRkYNClNFVCBGRUVE QkFDSyBPRkYNClNFVCBTUUxDQVNFIFVQUEVSDQpTRVQgU0VSVkVST1VUUFVUIE9OIFNJWkUgMTAw MDAwDQoNCkFDQ0VQVCB2X3NlcV9vd25lciBQUk9NUFQgJ0VudGVyIEV4aXN0aW5nIFNlcXVlbmNl IE93bmVyOiAnDQpBQ0NFUFQgdl9uZXdfb3duZXIgUFJPTVBUICdFbnRlciBOZXcgU2VxdWVuY2Ug T3duZXI6ICcNCkFDQ0VQVCB2X2Ryb3Bfc2VxIFBST01QVCAnSW5jbHVkZSBEcm9wIFNlcXVlbmNl LCBZIG9yIE46ICcNCiANClNQT09MIGNyZWF0ZV9zZXEuc3FsDQoNCkRFQ0xBUkUNCiAgIHZfbWF4 X3ZhbHVlCVZBUkNIQVIyKDIwKTsNCiAgIHZfY3ljbGUJVkFSQ0hBUjIoMjApOw0KICAgdl9vcmRl cglWQVJDSEFSMigyMCk7DQogICB2X2NhY2hlCVZBUkNIQVIyKDIwKTsNCiAgIHZfcHJpdglWQVJD SEFSMigyMCk7DQogICB2X2dyYW50ZWUJVkFSQ0hBUjIoMjApOw0KICAgdl9jb3VudAlOVU1CRVI7 DQoNCiAgIENVUlNPUiBDX1NFUSBJUw0KCVNFTEVDV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