Domanda

Here is the deal I'm trying to define MY_VARIABLE, which would be of a type MY_TABLE%ROWTYPE.

The problem is that MY_TABLE is dynamic and i receive it as a varchar2 variable, so something like

 TYPE my_variable 
   IS TABLE OF my_table%ROWTYPE;

wouldnt work because Compilation errors for PACKAGE BODY DENNIS.XXPORTER

'YOUR_TABLE_NAME' must name a table, cursor or cursor-variable

Now, how do i deal with that??

P S I need my_variable to fetch records from the ref cursor. And i used ref cursor not a cursor as i executed a query where table name (in from clause) was a variable

È stato utile?

Soluzione

You can't declare a variable whose data type is not known until runtime.

If you are trying to use dynamic SQL where the structure of the result set is also dynamic (if the number of columns and their data types are fixed for any table that is passed in, you could statically declare a record variable of an appropriate type), then you would realistically need to use the DBMS_SQL package to execute the statement, to gather data about the columns that are returned, and to bind appropriate variables into which you could fetch the data.

You can see an example of using the DBMS_SQL package in Tom Kyte's dump_csv function that dumps the results of an arbitrary SQL statement to a file.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top