Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:55:30+00:00 2026-06-08T17:55:30+00:00

I have this sql which copies (actually recreates) a sequence from a productive scheme

  • 0

I have this sql which copies (actually recreates) a sequence from a productive scheme to a test scheme in Oracle, how do i make a procedure from this that i can use as follows ? Suppose all grants are ok and all names are the same in the test scheme.

desired syntax

copy_sequence <name_of_sequence> <connectstring_prod_scheme> <connectstring_test_scheme> 

sql

connect test/testpw@db.srv;

declare
 val    number(21);
 s_sql varchar2(200);
begin
 --use the select on the productive db to get the current value
 select prod.seq.nextval into val from dual;
 s_sql := 'drop sequence seq';
 execute immediate s_sql;
 s_sql := 'create sequence seq minvalue 1 maxvalue 999999999999999999999 start with '||val||' increment by 1';
 execute immediate s_sql;
end;
/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:55:31+00:00Added an answer on June 8, 2026 at 5:55 pm

    Assuming your test/test user has the proper privileges (select any table, create sequence) and the schemas are in the same database:

    create procedure copy_sequence(seq VARCHAR2, prod_scheme VARCHAR2, test_scheme VARCHAR2)
    as
     val    number(21);
     s_sql varchar2(200);
    begin
     --either use the select on the productive db to get the current value + 1 
     execute immediate 'select '||prod_scheme||'.'||seq||'.nextval from dual' INTO val;
     --or use the select on ALL_SEQUENCES.LAST_NUMBER to get the current value (from APC's comment)
     execute immediate 'select last_number from all_sequences where sequence_owner = upper('''||prod_scheme||''') and sequence_name = upper('''||seq||''')' INTO val;
     s_sql := 'drop sequence '||test_scheme||'.'||seq;
     execute immediate s_sql;
     s_sql := 'create sequence '||test_scheme||'.'||seq||' minvalue 1 maxvalue 999999999999999999999 start with '||val||' increment by 1';
     execute immediate s_sql;
    end;
    /
    

    But you wouldn’t call this with connect strings but with schema names:

    -- first connect
    connect test/testpw@db.srv;
    -- then execute procedure
    exec copy_sequence( <name_of_sequence>, <prod_scheme>, <test_scheme>);
    -- or execute procedure more than once
    begin
     copy_sequence( <name_of_sequence1>, <prod_scheme>, <test_scheme>);
     copy_sequence( <name_of_sequence2>, <prod_scheme>, <test_scheme>);
    end;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a procedure which uses 2 sql databases - this is required in
Right now I have this SQL query which is valid but always times out:
I have this query which on executing in my sql command line client executes
I have this question in which I have a SQL Server Compact Edition database
I currently have this statement in my SQL View (SQL Server 2008 R2) which
I have a sql query which looks like this - NSString *createSQL = @SELECT
i have this sql query select * from table where name like ? but
I have this SQL statement: SELECT * FROM history WHERE (fk_person = 2119) AND
I have this SQL query from the logs select content = 5%id%201=1 from pages
I have a huge query which uses case/when often. Now I have this SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.