日期:2014-05-17  浏览次数:20751 次

Oracle中的游标怎么用?这里怎么报错了????
declare  
                s_Stemp   t_xt_qxdzsj.dzmc%type;
                s_Sreturn   varchar2(4000)   :=   ' ';
begin
declare  
                cursor   cur_temp   is
                              select   qxbh   ||   '# '   ||   dzmc   ||   '; '   as   colTemp   from   t_xt_qxdzsj;
                              --retCursor   t_xt_qxdzsj   %   rowtype;
                begin
                          Open   cur_temp;
                          Fetch   cur_temp   into   s_Stemp;
                          While   (cur_temp   %   NOTFOUND)   loop
                                      s_Sreturn   :=   s_Sreturn   +   to_char(s_Stemp);
                                      dbms_output.put_line(s_Stemp   ||   'While   In ');
                                      Fetch   cur_temp   into   s_Stemp;
                          End   loop;  
                          dbms_output.put_line( '我操了,没有的 ');
                end;
end;

------解决方案--------------------
declare
s_Stemp t_xt_qxdzsj.dzmc%type;
s_Sreturn varchar2(4000) := ' ';
cursor cur_temp is
select qxbh || '# ' || dzmc || '; ' as colTemp from t_xt_qxdzsj;
--retCursor t_xt_qxdzsj % rowtype;
begin
Open cur_temp;
Fetch cur_temp into s_Stemp;
While (cur_temp % NOTFOUND) loop
s_Sreturn := s_Sreturn + to_char(s_Stemp);
dbms_output.put_line(s_Stemp || 'While In ');
Fetch cur_temp into s_Stemp;
End loop;
dbms_output.put_line( '我操了,没有的 ');
end;
------解决方案--------------------
lz
把游表循环改成这样

LOOP

FETCH 。。。
。。。
EXIT WHEN cur_temp%NOTFOUND;
END LOOP