2010-06-09 5 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 "프로 시저/함수 정의"wh 앞에 와야합니다. ich는 목록 2에있다. –

+0

@Gary : Excellent, thanks! –

0

을 당신은뿐만 아니라 하위 절차에 사용할 수있는 커서를 선언하려면, 단지 추가 또 다른 익명의 블록을 :

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