473,395 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

table name substitution in pl/sql

how can we use a variable in the place of a tablename?

towner=scott
ttable_name=emp
select count(*) into totrows from towner.ttable_name;

ERROR at line 18:
ORA-06550: line 18, column 49:
PLS-00201: identifier 'TOWNER.TTABLE_NAME' must be declared
ORA-06550: line 18, column 15:
PL/SQL: SQL Statement ignored

I need to substitute different table names. How do I pass variable
names as table names? Towner and ttable_names are declared in the
declare section.

Thanks

Suresh
Jul 19 '05 #1
3 25724
Suresh wrote:
how can we use a variable in the place of a tablename?

towner=scott
ttable_name=emp
select count(*) into totrows from towner.ttable_name;

ERROR at line 18:
ORA-06550: line 18, column 49:
PLS-00201: identifier 'TOWNER.TTABLE_NAME' must be declared
ORA-06550: line 18, column 15:
PL/SQL: SQL Statement ignored

I need to substitute different table names. How do I pass variable
names as table names? Towner and ttable_names are declared in the
declare section.

Thanks

Suresh

Use Dynamic SQL, such as EXECUTE IMMEDIATE

Jul 19 '05 #2
Suresh wrote:
how can we use a variable in the place of a tablename?

towner=scott
ttable_name=emp
select count(*) into totrows from towner.ttable_name;

ERROR at line 18:
ORA-06550: line 18, column 49:
PLS-00201: identifier 'TOWNER.TTABLE_NAME' must be declared
ORA-06550: line 18, column 15:
PL/SQL: SQL Statement ignored

I need to substitute different table names. How do I pass variable
names as table names? Towner and ttable_names are declared in the
declare section.

Thanks

Suresh


Three ways to handle this:

1) use EXECUTE IMMEDIATE

2) use DBMS_SQL package

3) use a substitution variable
SELECT * FROM &TABLE_NAME WHERE .....

Option 1 and 2 will work anywhere

Option 3 will not work if you plan to deploy your PL/SQL as a stored
procedure/funtion/package.
hope this helps,
--
------------------------------------------------------------------------

*Michael Willer*
*Oracle & J2EE architect*

Jul 19 '05 #3
su******@yahoo.com (Suresh) wrote in message news:<2a**************************@posting.google. com>...
how can we use a variable in the place of a tablename?

towner=scott
ttable_name=emp
select count(*) into totrows from towner.ttable_name;

ERROR at line 18:
ORA-06550: line 18, column 49:
PLS-00201: identifier 'TOWNER.TTABLE_NAME' must be declared
ORA-06550: line 18, column 15:
PL/SQL: SQL Statement ignored

I need to substitute different table names. How do I pass variable
names as table names? Towner and ttable_names are declared in the
declare section.

Thanks

Suresh


Suresh,

Use a REF_CURSOR.

Frans H.
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mh | last post by:
Hello, I'm trying to create a table from a PHP script. >From what I read in my book about PHP and MySQL I should do something like that: $sql_query="CREATE TABLE '$num' ( 'variable1' ...
6
by: rh0dium | last post by:
Hi all, Basically I have a bunch of pluggins in a directory (METDIR). For each one of these templated pluggins I want to do a specific routine. Let's start with a basic template file...
3
by: John Baker | last post by:
Hi: At the outset let me admit that I screwed up! I have built a rather elaborate set of forms and sub forms starting with a client table, and going down to PO and Line item. This works very...
1
by: Brian Newman | last post by:
I have a form with five rows of text boxes, displaying data. For certain reasons, I can't bind these directly to data records, so I'm using code to load the data into an object, then manually get...
5
by: Murali | last post by:
In Python, dictionaries can have any hashable value as a string. In particular I can say d = {} d = "Right" d = "Wrong" d = "test" In order to print "test" using % substitution I can say
117
by: phil-news-nospam | last post by:
Is there really any advantage to using DIV elements with float style properies, vs. the old method of TABLE and TR and TD? I'm finding that by using DIV, it still involves the same number of...
1
by: fengqysll | last post by:
Hi: I am a table holding football match results using DB2 ID = matchid HN = Home team name HID = Home team id AN = Away team name ANID = Away Team id Eevent= use 1 for score, 2 for...
3
by: Suresh | last post by:
how can we use a variable in the place of a tablename? towner=scott ttable_name=emp select count(*) into totrows from towner.ttable_name; ERROR at line 18: ORA-06550: line 18, column 49:...
3
by: Andrea Raimondi | last post by:
Hello peers! I'm working on this application and I'm in need for some thoughtful advice :-p I have an SQLDataSource with params, select, etc. One of my params is the table name, which can be...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.