Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: create sequence in PL/SQL anonymous block - needs to be in separa
well,
declare
i pls_integer;
begin
execute immediate 'create
sequence temporary_sequence_s';
for i in 1..1000 loop
execute
immediate 'insert into t( n ) values( temporary_sequence_s.nextval )';
end loop;
commit;
execute immediate 'drop
sequence temporary_sequence_s'; end;
HTH, Michael www.atelo.com
Sent: Tuesday, September 04, 2001
16:30
Subject: create sequence in PL/SQL
anonymous block - needs to be in separa
Using Oracle 8.1.6 on Windows 2000
I try to use EXECUTE IMMEDIATE to create a sequence in an
anonyms PL/SQL block, and then immediately use it in an INSERT statement. The
INSERT statement fails saying "sequence does not exist." However, if I create
the sequence in a separate PL/SQL anonymous block immediately before the
anonymous PL/SQL block containing the insert, there is no error. A DROP
SEQUENCE that follows the insert is successful.
Any suggestions?
SQL> -- Creating sequence in same anonymous block: SQL> -- Insert statement doesn't recognize the SQL> -- sequence name SQL>
5 for i in 1..1000 6 loop 7 insert into t (n) <FONT
size=2> 10 end loop ; <FONT size=2> 11 commit ; <FONT size=2> 12 execute immediate 'drop sequencetemporary_sequence_s' ; 13 end ;
![]() |
![]() |