1

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

7
  • it's unclear if your input is a string or a refcursor. Commented Jun 25, 2013 at 14:38
  • my_table is of varchar2 Commented Jun 25, 2013 at 14:41
  • 1
    then you cant create a rowtype using only the name of the table (unless you write dynamic plsql code - which i'm guessing would be an overkill here). if you have a ref cursor you can just iterate it. Commented Jun 25, 2013 at 14:45
  • Yeah, but where would i fetch the values to? Commented Jun 25, 2013 at 14:47
  • As with each loop - i'll have a number of values to be stored. What variable/variables can i use for that? AND i do not know the table name or columns types in advance Commented Jun 25, 2013 at 14:48

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks, Your answer is quite useful. Currently im eximining the dbms_sql package.
that was it. THe example of a solution is somewhere on askTom website. I'll add a link sometime
@Dennis - Other than the link I had originally? Or are you saying you prefer an example other than the dump_csv procedure?
Oh, my bad :) Justin, the link you initially posted ( the dump_csv one) is the one i mentioned. For some reason i didnt notice it the first time I read your answer, so I wasted some time looking for the same info myself :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.