If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Using variable as table name in dynamic sql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-21-10, 16:45
das_bultz das_bultz is offline
Registered User
 
Join Date: Apr 2010
Posts: 4
Using variable as table name in dynamic sql

I am attempting to produce a 'parameterized view' in the form of a pipelined table function, where arguments to the function are used to build dynamic sql (a Select statement). The output of the Select would feed into a cursor. I would then fetch the rows of the cursor and pipe them out (after a little manipulation).

The problem that I have is that the parameters I am passing in need to be used to form the table names from which I am selecting. In other words, it's my From clause that is parameterized. All of the examples I have been able to find so far only show parameterized Where clauses.

Every method I have attempted using Table(myVar), Table(cast(myVar as SomeTableType)), etc has failed.

Can anyone share a working example of dynamic sql (preferably feeding a cursor), where the sql has a parameterized From clause?

Thank you in advance for your help!

Neil
Reply With Quote
  #2 (permalink)  
Old 04-21-10, 18:13
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Quote:
Originally Posted by das_bultz View Post
Can anyone share a working example of dynamic sql (preferably feeding a cursor), where the sql has a parameterized From clause?
What's wrong with the examples in the manual?

For example this one:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/dynamic.htm#CHDJHAHE
Reply With Quote
  #3 (permalink)  
Old 04-22-10, 01:50
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
Quote:
Originally Posted by das_bultz View Post
I am attempting to produce a 'parameterized view' in the form of a pipelined table function, where arguments to the function are used to build dynamic sql (a Select statement).
...
Every method I have attempted using Table(myVar), Table(cast(myVar as SomeTableType)), etc has failed.
For this kind of collection access, there is no need of dynamic SQL (it shall be called statically), so I just wonder, what statement did you write and what was the exact failure description. By the way, collections are described in PL/SQL User's Guide and Reference, available with other Oracle documentation books e.g. online on http://tahiti.oracle.com/
Reply With Quote
  #4 (permalink)  
Old 04-22-10, 07:37
mishaalsy mishaalsy is offline
Registered User
 
Join Date: Aug 2009
Posts: 262
Passing table name into a Cursor - PL/SQL

if this kind of thing satisfy your need ( nearly or even barely ) ...
do tell
Reply With Quote
Reply

Tags
dynamic sql, parameterized view, pipelined function, table function

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On