I have used sys_refcursor before to return the data of select statements.But,I am using execute immediate here,so I am not able to use the sys_refcursor in execute immediate statement.
Before I used to do
R_C OUT SYS_REFCURSOR //refcursor
OPEN R_C FOR //it used to handle the return of all select statement
SELECT * FROM table_name;
But ,I tried execute immediate today and I am not able to print the data of select statement. So,following I tried is:
CREATE OR REPLACE PROCEDURE OT.check_data(DATA1 number,R_C OUT SYS_REFCURSOR)
IS
vquery long;
BEGIN
vquery :='select * from ot.employee ';
if data1 = 10 then
vquery := vquery||' where deptno in (10)';
else
vquery := vquery||' where deptno in (20,30)';
end if;
execute immediate vquery;
END;
/
exec OT.check_data(10);
The procedure is working fine,but I am unable to see the data of select statement.How can I display the data of execute immediate in my console?I am using toad.