Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: A Dynamic SQL problem.....Help!!
Violin,
You can code a loop to fetch the rows from your 'cursor_name' one by one and insert them into a table (temp_table), then open the emp_cur refcursor on a select from temp_table. You might be able to do the same thing by poking them into a PL/SQL table and opening your refcursor on the PL/SQL table, but I haven't tried that.
You can add a column to hold the process id to handle multiple users referencing the same temp_table simultaneously. (The temp_table is a normal oracle table, we use a standard surrogate key domain so we can usually get away with only the one temp_table).
Here is an example:
CREATE OR REPLACE
PROCEDURE SP_DIARY_LIST
( AWHERE IN VARCHAR2, OUTREC IN OUT AXIOM_DIARY_PKG.TRC_DIARY_LIST) AS v_CursorID INTEGER; v_SelectStmt VARCHAR2(4000); v_DiaryNoteID INTEGER;
begin
-- -- LIST DIARY NOTES FOR THE SPECIFIED USER. IF USERID IS NULL THEN CURRENT USER. --
DBMS_SQL.PARSE(v_CursorID, v_SelectStmt, DBMS_SQL.V7);
DBMS_SQL.DEFINE_COLUMN(v_CursorID, 1, v_DiaryNoteID); --*** You need to look at
this!!!
v_Dummy := DBMS_SQL.EXECUTE(v_CursorID);
LOOP
IF DBMS_SQL.FETCH_ROWS(v_CursorID) = 0 THEN
EXIT;
END IF;
DBMS_SQL.COLUMN_VALUE(v_CursorID, 1, v_DiaryNoteID);
INSERT INTO TEMP_TABLE (sessionID, num_val) VALUES (v_SessionID, v_DiaryNoteID);
END LOOP; DBMS_SQL.CLOSE_CURSOR(v_CursorID);
DELETE FROM TEMP_TABLE
WHERE TEMP_TABLE.sessionID = v_SessionID;
END SP_DIARY_LIST ;
Hope this helps, and if anyone has a better way please let me know!
Regards, David.
Violin wrote:
> Hello,
> If I create a procedure for SELECT statement in static SQL.
> Like this:
> create or replace procedure emp_list(
> dept in number,
> emp_cur in out emp_pkg.empcurtyp)
> is
> begin
> open emp_cur for
> select empno,ename,job from emp where deptno = dept;
> end;
> /
> create or replace package emp_pkg as
> type emptyp is record
> (empno number,
> ename varchar2(10),
> job varchar2(9));
> type empcurtyp is ref cursor return emptyp;
> end;
> /
>
>
>
>
>
>