Solved

bind variable in query to sys_refcursor

Posted on 2012-04-11
4
776 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 73

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 73

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

773 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