Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 804
  • Last Modified:

bind variable in query to sys_refcursor

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
Focker513
Asked:
Focker513
  • 2
3 Solutions
 
sdstuberCommented:
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
 
slightwv (䄆 Netminder) Commented:
Table names cannot be bind variables.

try:

vQuery:='select  * from ' || pTName;
0
 
sdstuberCommented:
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
 
Focker513Author Commented:
Thanks for the quick the responses and the deeper explanations.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now