I am trying to create a procedure in which another procedure is being called and it returns pl/sql table type. How to collect values of plsql table into ref cursor and return as OUT type refcursor. Please help.
Thanks!
I have this piece of Code : p_rec is table type
DECLARE
p_rec PORTAL_LOAD_PKG.header_tab@test_link;
p_status VARCHAR2(200);
BEGIN
DASHBOARD_PRC@test_link('XYZ LIMITED', p_rec, p_status);
END;
Above code is working fine but my requirement is to create a procedure which returns the values of p_rec in refcursor.
Finally resolved.
First we have to create a Object and table type locally. Object definition should be same as your record type which is declared on remote DB.
CREATE OR REPLACE TYPE dashboard_obj AS OBJECT (
i_num VARCHAR2(500),
desc VARCHAR2(1000),
od_num VARCHAR2(200),
i_amount NUMBER,
amount_paid NUMBER,
status VARCHAR2(200),
terms_date DATE,
i_id NUMBER,
v_id NUMBER
);
After that create table type of that object.
CREATE OR REPLACE TYPE tab1 IS
TABLE OF dashboard_obj;
Now Create procedure :
CREATE OR REPLACE PROCEDURE proc_test (
recordset OUT SYS_REFCURSOR
) IS
p_rec portal_load_pkg.header_tab@test_link;
p_status VARCHAR2(200);
obj dashboard_obj;
v_tab tab1 := tab1 ();
BEGIN
dashboard_prc@test_link ( 'XYZ LIMITED',p_rec,p_status );
FOR i IN 1.._rec.count LOOP
v_tab.extend;
v_tab(v_tab.count) := dashboard_obj(p_rec(i).i_num,
p_rec(i).desc,
p_rec(i).od_num,
p_rec(i).i_amount,
p_rec(i).amount_paid,
p_rec(i).status,
p_rec(i).terms_date,
p_rec(i).i_id,
p_rec(i).v_id
);
END LOOP;
OPEN recordset FOR SELECT
*
FROM
TABLE ( v_tab );
END;
If there is any other solution, please let me know. Thanks!