Home » SQL & PL/SQL » SQL & PL/SQL » Need to reset sequence numbers after an import
Need to reset sequence numbers after an import [message #19462] Wed, 20 March 2002 08:02 Go to next message
Rich
Messages: 14
Registered: March 2002
Junior Member
I'm doing a partial database load through an export file. The problem is I also need to reset all of the sequences used to seed the IDs for those tables.

There doesn't seem to be a way to specify which sequences to include in an export....I'm using the tables=() parameter of the exp function to specify which tables to export/import, but I can't see how to include the sequences I use for those tables as well.

My other though is to use a script after loading to reset them all, but this fails. Any ideas?

declare

v_next_id number;

begin

select max(detail_id)+1 into v_next_id from aa_order_detail;
drop sequence aa_order_detail_seqno;
commit;
CREATE SEQUENCE aa_order_detail_seqno
START WITH v_next_id
INCREMENT BY 1
NOMINVALUE
NOMAXVALUE
NOCYCLE
NOCACHE
NOORDER;
commit;

end;
Re: Need to reset sequence numbers after an import [message #19464 is a reply to message #19462] Wed, 20 March 2002 08:10 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
In order to run DDL (create/alter/drop) in an anonymous block, you will need to use dynamic SQL:

execute immediate 'create sequence a_order_detail_seqno START WITH ' || v_next_id || ' INCREMENT BY ...';


You also do not need the commit statements since a commit is implicit with each DDL statement.
Previous Topic: Oracle SQL*Plus and Microsoft Access
Next Topic: CASE statement in a Stored Procedure
Goto Forum:
  


Current Time: Tue Apr 23 10:47:16 CDT 2024