Domanda

I have a lot of named cursors in PL/SQL like this:

cursor MY_CURSOR_01 is select * from my_table_01;
cursor MY_CURSOR_02 is select * from my_table_02;

I want to use them in dbms_xmlgen.newContext procedure which expects a SYS_REFCURSOR or a VARCHAR2 containing the actual query.

I already know that I could do:

dbms_xmlgen.newContect('select * from my_table_01');

But I would like to reuse the existing cursors I have, without rewriting them as string queries.

Any ideas? I am on Oracle 10gR2.

È stato utile?

Soluzione

I don't think such a function exists, because Oracle's language specification doesn't allow for cursor objects to be passed as parameters. Unless Oracle has used some magic somewhere, there's just no way to generically reference a cursor without using a refcursor.

However, you don't need to embed your SQL in a string to use a sys_refcursor. Here's a very simple example showing that a sys_refcursor can be opened using static SQL:

DECLARE
   c SYS_REFCURSOR;
BEGIN
   OPEN c FOR SELECT * FROM DUAL;
   CLOSE c;
END;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top