将记录数组转换为refcursor

时间:2010-09-03 12:50:40

标签: oracle

问题是如何将l_array作为refcursor返回, 由于我使用的接口可以轻松处理光标而不是记录数组。

Plz帮助

  create or replace package sample 
  TYPE r_type is record( code number; description varchar2(50)); 
  TYPE tr_type IS TABLE OF r_type; l_rarray tr_type ; ind number:=0; 

  PROCEDURE getdata() IS
     CURSOR cur IS
        SELECT empid, empname, place, location FROM emp;
     TYPE epmid_aat IS TABLE OF emp.empid%TYPE INDEX BY BINARY_INTEGER;
     l_empid empid_aat;
  BEGIN
     k := 1;
     FOR j IN (SELECT DISTINCT empid FROM emp)
     LOOP
        l_empid(k) := j.empid;
        k := k + 1;
     END LOOP;
     FOR i IN cur
     LOOP
        FOR k IN l_empid.first .. l_empid.last
        LOOP
           IF l_empid(k) = i.empid THEN

              procedure2(i.emp_id);
           END IF;
        END LOOP;
     END LOOP;

  END getdata();

  PROCEDURE procedure2
  (
     empid_in       IN NUMBER,
     description_in IN VARCHAR2(20)
  ) IS
  BEGIN
     lrec.code := empid_in;
     lrec.description := description_in;
     l_rarray(ind) := lrec;
     ind := ind + 1;
  END procedure2;

  end;

2 个答案:

答案 0 :(得分:2)

我认为应该是这样的:

OPEN YourRefCursor
 FOR SELECT * FROM TABLE (Cast(l_rarray AS tr_type)); 

答案 1 :(得分:1)

像这样。

    TYPE r_type is record ( code number; 
                   description varchar2(50)
                  ); 
    TYPE tr_type IS TABLE OF r_type; 

    l_rarray tr_type ;

    SELECT r_type(empid, empname)
    BULK COLLECT INTO l_rarray
    FROM emp;

    OPEN YourRefCursor
    SELECT *
    FROM TABLE (Cast(l_rarray AS r_type));