I do have a working query to get resultset as per my requirement ,but the problem is am unable to view the result set in Oracle sql developer .
CREATE OR REPLACE PROCEDURE SP_GETDATA(
id in number,
result_cursor out sys_refcursor
)AS
BEGIN
DECLARE v_sql varchar2(2000);
BEGIN
v_sql:-'select * from(select col1,col2,col3 from tab1)
pivot (max(col3) for col1 in(';
for i in (select col1 from tab2)
LOOP
v_sql:=v_sql||i.col1||',';
END LOOP;
v_sql:=RTRIM(v_sql,',')||')) ORDER BY col2';
OPEN result_cursor for v_sql;
END;
END ;
/
and am trying to call the stored procedure with the following commands,
VARIABLE cursor_test refcursor;
exec SP_GETDATA(1,:cursor_test);
print cursor_test;
which give me PL/SQL procedure successfully completed and no result. How could I get the result set from the above? while executing query generated inside v_sql gives me the exact output.
Dummy table/column names don't help much so I used Scott's sample schema to try your code.
Procedure:
Testing:
Does it work in SQL Developer? Yes:
Or, you can run the procedure (from Object Navigator) and view "Output Variables"):