Hi Guys,
I have been struggling to with creating temp table within a procedure and returning a cursor ref.
Basically, I am trying to convert my in-line sql into procedures which returns cursor ref.
Using inline SQL, I had created series of temporary tables - output of temp tables used as input to other temp table within sql. However, due to audit issues, I had to convert all inline sql to procedures.
I have been trying to achieve whatever I had achieved using inline sql. Howver, not been able to create temp tables within a procedure and return a cursor ref.
Any expert advise on how do I achive this?
I am able to create temp tables using below.
declare
l_tname varchar2(30) default 'temp_table_' || userenv('sessionid');
begin
execute immediate 'create global temporary table ' ||
l_tname || ' on commit delete rows as
select * from all_tables where 1=0 ';
end;
I am trying to bundle above into procedure and return a cursor ref with, but not sure how do I get this?
PROCEDURE test(v_cur OUT sys_refcursor) IS
BEGIN
OPEN v_cur FOR
(execute immediate 'create global temporary table ' ||
l_tname || ' on commit preserve rows as
select * from imp_desk '
SELECT * FROM l_tname);
END;
Regards,
Mohit
I have been struggling to with creating temp table within a procedure and returning a cursor ref.
Basically, I am trying to convert my in-line sql into procedures which returns cursor ref.
Using inline SQL, I had created series of temporary tables - output of temp tables used as input to other temp table within sql. However, due to audit issues, I had to convert all inline sql to procedures.
I have been trying to achieve whatever I had achieved using inline sql. Howver, not been able to create temp tables within a procedure and return a cursor ref.
Any expert advise on how do I achive this?
I am able to create temp tables using below.
declare
l_tname varchar2(30) default 'temp_table_' || userenv('sessionid');
begin
execute immediate 'create global temporary table ' ||
l_tname || ' on commit delete rows as
select * from all_tables where 1=0 ';
end;
I am trying to bundle above into procedure and return a cursor ref with, but not sure how do I get this?
PROCEDURE test(v_cur OUT sys_refcursor) IS
BEGIN
OPEN v_cur FOR
(execute immediate 'create global temporary table ' ||
l_tname || ' on commit preserve rows as
select * from imp_desk '
SELECT * FROM l_tname);
END;
Regards,
Mohit