2010-06-09 54 views
5

我有一個匿名的pl/sql塊,其中聲明瞭一個過程以及一個遊標。如果我在遊標之前聲明過程,它會失敗。是否有要求在程序之前聲明遊標?聲明在匿名pl/sql塊中的順序

對於pl/sql塊中的聲明順序,還有哪些其他規則?

這工作:

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

這種失敗,錯誤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; 

回答

12

光標,變量,常量和類型需要前包/函數聲明。如果你想聲明的遊標提供給子過程以及

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

文檔引用這裏 http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/block.htm#i32791 它不是很清楚,但「項目聲明」(如變量)在列表中1並且必須在「程序/函數定義」之前出現ich在列表2中。 – 2010-06-09 23:17:06

+0

@Gary:非常好,謝謝! – 2010-06-10 14:51:50

0

,只需添加另一個匿名塊:

這一次會失敗太

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