运行PL / SQL程序时出错

时间:2013-12-07 07:31:20

标签: sql oracle plsql

declare 
numbers department.dpt_no%type ;
cursor sc is
 select dpt_no into numbers from department ;
begin
open sc;
loop sc
fetch sc into numbers;
dbms_output.put_line('department numbers is'||numbers);
end loop;
close sc;
end;

执行上述程序时,显示错误,如

PLS-00103: Encountered the symbol "FETCH" when expecting one of the following:

   := . ( @ % ;
The symbol ";" was substituted for "FETCH" to continue.
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

我的代码中有错误请告诉我

2 个答案:

答案 0 :(得分:1)

很确定你不应该做LOOP SC

此外,您需要在执行NOTFOUND

时检查FETCH

尝试:

loop
    fetch sc into numbers;
    exit when sc%notfound;
    dbms_output.put_line('department numbers is'||numbers);
end loop;

请参阅LOOP documentation

如果你出于某种原因想要在你的循环中想要一个标签,你就会使用这种语法:

enter image description here

答案 1 :(得分:0)

尝试在循环后取出“sc”。

open sc;
loop
   fetch sc into numbers;
   exit when sc%notfound;
   dbms_output.put_line('department numbers is'||numbers);
end loop;