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

非常急动态游标问题
CREATE   OR   REPLACE   PROCEDURE   YKBZDB.P_BZJD_YWTJ_YDGCMX(err_flag   out   number,err_msg   out   varchar2)
AS

declare

    type   MyCursor   is   REF   CURSOR   ;
    cur   MyCursor;
    rst   xx%rowtype;
    sqlstr   varchar2(400);
    tablename   varchar2(20);
begin
    tablename   :=   'bzjd_ydsq ';
    sqlstr   :=   'select   *   from   '   ||   tablename;
   
 
    open   cur   for   sqlstr;
   
    loop
    fetch   cur   into   rst;
    exit   when   cur%notfound;
        --要处理东西
    end   loop;    
end;
end;
为什么现在老提示我把declare换成begin.到底那错了。

------解决方案--------------------
就应该用begin呀.
------解决方案--------------------
先begin
------解决方案--------------------
CREATE OR REPLACE PROCEDURE YKBZDB.P_BZJD_YWTJ_YDGCMX(err_flag out number,err_msg out varchar2)
AS
begin
declare
type MyCursor is REF CURSOR ;
cur MyCursor;
rst xx%rowtype;
sqlstr varchar2(400);
tablename varchar2(20);
begin
--
tablename := 'bzjd_ydsq ';
sqlstr := 'select * from ' || tablename;
open cur for sqlstr;
loop
fetch cur into rst;
exit when cur%notfound;
--要处理东西
end loop;
close cur ;//关闭游标
end;

end;
------解决方案--------------------
type MyCursor is REF CURSOR ;
这样定义 一般是用于返回游标吧

一般情况下 直接声明游标 打开游标 操作 关闭游标 就行了吧
------解决方案--------------------
CREATE OR REPLACE PROCEDURE YKBZDB.P_BZJD_YWTJ_YDGCMX(err_flag out number,err_msg out varchar2)
AS
type MyCursor is REF CURSOR ;
cur MyCursor;
rst xx%rowtype;
sqlstr varchar2(400);
tablename varchar2(20);
begin
tablename := 'bzjd_ydsq ';
sqlstr := 'select * from ' || tablename;


open cur for sqlstr;

loop
fetch cur into rst;
exit when cur%notfound;
--要处理东西
end loop;
end YKBZDB.P_BZJD_YWTJ_YDGCMX;