Ad order in anonymous pl / sql block

I have an anonymous pl / sql block with a procedure declared inside it, as well as a cursor. If I declare a procedure before the cursor, it fails. Is there a requirement for cursors to be declared before procedures?

What other rules exist for the declaration order in the pl / sql block?

It works:

DECLARE
 cursor cur is select 1 from dual;
 procedure foo as begin null; end foo;
BEGIN
 null;
END;

Error with error PLS-00103: Encountered the symbol "CURSOR" when expecting one of the following: begin function package pragma procedure form

DECLARE
 procedure foo as begin null; end foo;
 cursor cur is select 1 from dual;
BEGIN
 null;
END;
+5
source share
2 answers

Cursors, variables, constants, and types must be declared before packages / functions.

This one won't work either:

DECLARE
 procedure foo as begin null; end foo;
 x VARCHAR2(10);
BEGIN
 null;
END;
+13
source

If you want to declare a cursor that is available for a helper procedure, just add another anonymous block:

DECLARE
 cursor cur is select 1 from dual;
BEGIN
 DECLARE
  procedure foo as begin null; end foo;
 BEGIN
  null;
 END;
END;
0
source

All Articles