Solved

bind variable in query to sys_refcursor

Posted on 2012-04-11
4
778 Views
Last Modified: 2012-04-11
I have a simple query to select a table into a ref_cursor but I keep receiving either an "invalid table_name" or a "bad bind variable" when executing


Please show me the correct syntax:

PROCEDURE GET_TABLE ( pTName in varchar2, RESULT out sys_refcursor) as

vQuery varchar2(75);
BEGIN
  vQuery:='select  * from :1';
 
     open RESULT for vQuery using pTName;





END GET_TABLE;
0
Comment
Question by:Focker513
  • 2
4 Comments
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 200 total points
ID: 37834447
you can't use bind variables to specify objects,  only values within those objects (i.e. column values)


vQuery:='select  * from ' || ptname;

open RESULT for vQuery;
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 100 total points
ID: 37834454
Table names cannot be bind variables.

try:

vQuery:='select  * from ' || pTName;
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 200 total points
ID: 37834468
the purpose of bind variables is save parsing for similar queries


select * from table1;

is not the same query as

select * from table2;

you have to validate both tables do, in fact, exist, resolve different sets of synonyms, different sets of permissions,
if the objects are actually views rather than real tables, then different parsing within the views, etc.


binds are for things like this...

select * from table1 where column1 = :x;

Now I can query that multiple times for different values of x.
the objects and columns didn't change, so it's the same query, same synonyms, same permissions, same parsing.

Only the referenced value is changeable, therefore it is bindable
0
 

Author Closing Comment

by:Focker513
ID: 37834480
Thanks for the quick the responses and the deeper explanations.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MULTIPLE DATE QUERY 15 91
Distinct values from all columns in a table?? PL SQL 4 48
form builder not starting 3 55
Creation date for a PDB 5 39
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question