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

Oracle 匿名pl/sql块中声明的顺序,oracle,plsql,Oracle,Plsql,我有一个匿名pl/sql块,其中声明了一个过程和一个游标。如果我在游标之前声明过程,它将失败。是否有在程序之前声明游标的要求 pl/sql块中的声明顺序还有哪些其他规则 这项工作: DECLARE cursor cur is select 1 from dual; procedure foo as begin null; end foo; BEGIN null; END; 此操作失败,出现错误PLS-00103:在需要以下操作之一时遇到符号“游标”:开始功能包pragma程序表 DECL

我有一个匿名pl/sql块,其中声明了一个过程和一个游标。如果我在游标之前声明过程,它将失败。是否有在程序之前声明游标的要求

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

这项工作:

DECLARE
 cursor cur is select 1 from dual;
 procedure foo as begin null; end foo;
BEGIN
 null;
END;
此操作失败,出现错误
PLS-00103:在需要以下操作之一时遇到符号“游标”:开始功能包pragma程序表

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

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

这一次也会失败:

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

如果要声明子过程也可用的游标,只需添加另一个匿名块:

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

文档参考在这里,它不是很清楚,但是“项声明”(例如变量)在列表1中,必须在列表2中的“过程/函数定义”之前。修改代码时很容易遗漏!我在游标之前声明了一个函数,我得到的结果是:ORA-06550:第XXX行,第X列:PLS-00103:在期望以下操作之一时遇到符号“游标”:begin function pragma procedure