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;
/
Assuming your test/test user has the proper privileges (select any table, create sequence) and the schemas are in the same database:
But you wouldn’t call this with connect strings but with schema names: