匿名pl/sql块中的声明顺序

aw *_*rud 5 oracle plsql

我有一个匿名的pl/sql块,其中包含一个声明的过程以及一个游标.如果我在光标之前声明该过程则失败.是否要求在程序之前声明游标?

pl/sql块中的声明顺序还有哪些其他规则?

这有效:

DECLARE
 cursor cur is select 1 from dual;
 procedure foo as begin null; end foo;
BEGIN
 null;
END;
Run Code Online (Sandbox Code Playgroud)

这失败了,错误 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;
Run Code Online (Sandbox Code Playgroud)

Pet*_*ang 13

需要在包/函数之前声明游标,变量,常量和类型.

这个也会失败:

DECLARE
 procedure foo as begin null; end foo;
 x VARCHAR2(10);
BEGIN
 null;
END;
Run Code Online (Sandbox Code Playgroud)

  • 文档参考在这里http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/block.htm#i32791这不是很清楚,但"项目声明"(例如变量)在列表1,必须在列表2中的"过程/函数定义"之前. (2认同)