蟾蜍:如何循环的选择
我使用的蟾蜍,有一个名为MyTable表一个结果,它有一个名为INFO柱:
 信息
 ABCD 
 EFGH 
 IJKL 
蟾蜍:如何循环的选择
我需要的是将INFO的元素一个接一个地完成任务。所以,我认为我需要的东西,象下面这样:
foreach (select INFO from MyTable)     print 
end 
我试图谷歌,似乎我应该使用光标。所以,我想是这样的:
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.
回答:
显然要执行PL/SQL块,但DEF不是PL/SQL的一部分。 尝试执行下列程序:
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; 
你也可以做同样的使用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; 
以上是 蟾蜍:如何循环的选择 的全部内容, 来源链接: utcz.com/qa/265106.html





