2016-07-14 3 views
0
내가 두꺼비를 사용하고 있는데 MyTable라는 이름의 테이블이

의 결과 집합, 그것은 INFO라는 이름의 열이 방법 루프 :
정보
ABCD
EFGH
IJKL를
두꺼비 : 선택

내가 필요로하는 것은 INFO의 요소를 하나씩 가지고 작업을 수행하는 것입니다. 그래서 나는 다음과 같은 것을 필요가 있다고 생각 :

foreach (select INFO from MyTable) 
    print 
end 

나는 Google에 시도하고 내가 커서를 사용해야하는 것으로 보인다. 그래서 나는이 같은 시도 :

DEF msg varchar2(15); 

cursor cr is 
    select info from mytable; 

begin 
    OPEN cr; 
    loop 
    FETCH cr into msg; 
    exit when cr%NOTFOUND; 
    -- do job 
    end loop; 
    CLOSE cr; 
end; 

그러나 나는 오류가 발생했습니다 :

cursor cr is
Error at line 3
ORA-00900: invalid SQL statement
Script Terminated on line 3.

답변

1


은 분명히 당신이 PL/SQL 블록을 실행하고 싶지만, DEF은 PL/SQL의 일부가 아닙니다. 동일 cursor for loop statement

begin 
    for rec in (
    select info from mytable 
) loop 
     -- do job (you can reference info by using rec.info) 
    end loop; 
end; 
를 사용하여 당신은 또한 할 수

declare 
msg varchar2(15); 
cursor cr is 
    select info from mytable; 
begin 
    OPEN cr; 
    loop 
    FETCH cr into msg; 
    exit when cr%NOTFOUND; 
    -- do job 
    end loop; 
    CLOSE cr; 
end; 

: 다음 블록을 실행하려고