[英]Order of declaration in an anonymous pl/sql block
I have an anonymous pl/sql block with a procedure declared inside of it as well as a cursor. 我有一个匿名的pl / sql块,其中包含一个声明的过程以及一个游标。 If I declare the procedure before the cursor it fails.
如果我在光标之前声明该过程则失败。 Is there a requirement that cursors be declared prior to procedures?
是否要求在程序之前声明游标?
What other rules are there for order of declaration in a pl/sql block? pl / sql块中的声明顺序还有哪些其他规则?
This works: 这有效:
DECLARE
cursor cur is select 1 from dual;
procedure foo as begin null; end foo;
BEGIN
null;
END;
This fails with error PLS-00103: Encountered the symbol "CURSOR" when expecting one of the following: begin function package pragma procedure form
这失败并出现错误
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;
Cursors, variables, constants and types need to be declared before packages/functions. 需要在包/函数之前声明游标,变量,常量和类型。
This one would fail too: 这个也会失败:
DECLARE
procedure foo as begin null; end foo;
x VARCHAR2(10);
BEGIN
null;
END;
If you want to declare a cursor that is available to the sub procedure as well, 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.