Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concatenate variables to create a valid table name?

Status
Not open for further replies.

Slippenos

MIS
Apr 22, 2005
333
0
0
US
I am in the process of creating a procedure. In this procedure I need to access another database.

The database that I want to select from is the parameter passed in (customer id). Each customer has their own database.

Observe:
Code:
......
BEGIN

SELECT ID INTO V_USE_ID
FROM DATA_ || IN_CUSTOMER_ID || .THISTABLE@THISDBLINK
WHERE RECORDTYPE = 'T'
AND REFERENCEID = IN_PARTNER_ID;
......
Is there anyway to create a valid table name in this manner?

Thanks in advance,
Mike

[blue]Go to work to learn. Don't go to work to earn.[/blue]
 
I found an appropriate answer (I'm new to pl/sql)

When dealing with dynamic sql such as this, I used execute immediate:
Code:
......
BEGIN

EXECUTE IMMEDIATE
 'SELECT ID ' || 
 'FROM DATA_' || IN_CUSTOMER_ID || '.THISTABLE@THISDBLINK ' ||
 'WHERE ........ '

[blue]Go to work to learn. Don't go to work to earn.[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top