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

存储过程向其中的游标传值的难解问题,单独执行可以取到数据,而放在存储过程中进行传值取不到数据
CREATE   OR   REPLACE   PROCEDURE   proc_test(                                                          
      a                             IN               INTEGER,    
      b                             IN               VARCHAR2,            
      errnum                   OUT             NUMBER
)
AS
      v_form_rec       tabletest%ROWTYPE;
      retval               NUMBER   (6);
     
BEGIN
      retval   :=   0;
      DECLARE
            CURSOR   rowtable_cursor
            IS
                  SELECT   *   FROM   tabletest     WHERE   id=   a   AND   id_code   IN   (
                  SELECT   id_code   FROM   tabletest1     WHERE   SUBSTR   (idNum,   b,   1)   =   '1 ')  
                  ORDER   BY   id;
      BEGIN
            OPEN   rowtable_cursor;

            FETCH   rowtable_cursor
              INTO   v_form_rec;

            WHILE   (rowtable_cursor%FOUND)
            LOOP
                    //some   method
            end   loop;
end   proc_test;


就是说通过传值后的rowtable_cursor中的sql语句放在sql   editor里是有数据的,但是放在存储过程中却取不到数据,不能执行loop循环,望达人相助!解决即给分!

------解决方案--------------------
CREATE OR REPLACE PROCEDURE proc_test(
a IN INTEGER,
b IN VARCHAR2,
errnum OUT NUMBER
)
AS
v_form_rec tabletest%ROWTYPE;
retval NUMBER (6);

CURSOR rowtable_cursor
IS
SELECT *
FROM tabletest
WHERE id = a
AND id_code IN (SELECT id_code FROM tabletest1 WHERE SUBSTR (idNum, b, 1) = '1 ')
ORDER BY id;


BEGIN
retval := 0;
OPEN rowtable_cursor;
LOOP
FETCH rowtable_cursor
INTO v_form_rec;

EXIT WHEN rowtable_cursor%NOTFOUND;
//some method
end loop;
close rowtable_cursor;
end proc_test;
------解决方案--------------------
在while循环体内还需要fetch,否则之执行一次
------解决方案--------------------