tags:

views:

60

answers:

1

The question is how to return the l_array as refcursor, Since the interface i am using can handle cursor easily rather than an array of record.

Plz help

  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;
A: 

Something like this.

    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));
Michael Pakhantsov
One more clarifiction in the procedure2we are appending the lrec to l_rarray which is a global array.It is throwing the following errorORA-06532: Subscript outside of limithow to do that
K Ratnajyothi
Actually you are fetching the data into a_array using the bulk collect....But there are number of records appended in the array..My question is hoe to convert this array of records into a cursor
K Ratnajyothi
@K Ratnajyothi, you need extend array by executing l_array.extend; Array of records can be converted to cursor by using TABLE CAST as shown in example.
Michael Pakhantsov
@Michael: You need to use `tr_type` in your CAST, not `r_type`. Also, I believe those types need to be created as schema objects (CREATE TYPE ...) in order to be used in SQL statements.
Dave Costa
open mycursorSELECT * FROM TABLE (Cast(l_rarray AS tr_type)); is throwing an error PL/SQL: ORA-00902: invalid datatype
K Ratnajyothi