oracle 匿名 pl/sql 块中的声明顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3006972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Order of declaration in an anonymous pl/sql block
提问by aw crud
I have an anonymous pl/sql block with a procedure declared inside of it as well as a cursor. If I declare the procedure before the cursor it fails. Is there a requirement that cursors be declared prior to procedures?
我有一个匿名 pl/sql 块,其中声明了一个过程以及一个游标。如果我在游标之前声明该过程,它将失败。是否要求在过程之前声明游标?
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;
回答by Peter Lang
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;
回答by Jeffrey Kemp
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;