473,395 Members | 1,915 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.

Could I use a host variable for replacing the table name in SQC program?

Hello all,

I would like to use same SQL statement in my SQC program for several
tables
I tried something like that:

- sql_sts="SELECT col1, col2 FROM ?"
- EXEC SQL PREPARE dsql FROM :sql_sts;
- EXEC SQL DECLARE cTab CURSOR WITH HOLD FOR dsql;
- EXEC SQL OPEN cTab USING :tabName;
EXEC SQL FETCH cTab;
- EXEC SQL CLOSE cTab;

where tabName is a parameter, and it does not work!
Could I use a host variable like this way in my SQC?
Thanks for your help

Y.

Jul 6 '06 #1
3 1855
Which db2 version and fixpak on which operating system?
What is the exact error that you get ?

Jul 7 '06 #2
Which db2 version and fixpak on which operating system?
We have DB2 v8.1.1.96 FixPak 10 on AIX 5.2
What is the exact error that you get ?
I got SQLCODE=-727 and SQLSTATE=56098

I think the table name can not be used as parameter in a prepare
statement? Is that correct?

Thanks

D.

Jul 7 '06 #3
young wrote:
Hello all,

I would like to use same SQL statement in my SQC program for several
tables
I tried something like that:

- sql_sts="SELECT col1, col2 FROM ?"
- EXEC SQL PREPARE dsql FROM :sql_sts;
- EXEC SQL DECLARE cTab CURSOR WITH HOLD FOR dsql;
- EXEC SQL OPEN cTab USING :tabName;
EXEC SQL FETCH cTab;
- EXEC SQL CLOSE cTab;

where tabName is a parameter, and it does not work!
Could I use a host variable like this way in my SQC?
Thanks for your help
You can't do that. If you have static embedded SQL, then DB2 would attempt
to compile the statement. And that's impossible if DB2 doesn't know the
table it is working with. If you have dynamic embedded SQL (it looks that
way to me), you don't really need a parameter marker there. Just build the
SQL statement with the actual table name using sprintf() or other means.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Jul 11 '06 #4

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

Similar topics

6
by: Geoff Berrow | last post by:
The host of one of the domains I manage has installed 4.3.11-dev and as a result file uploads no longer work with Internet Explorer. Worth keeping an eye out for. In the meantime I now need to...
6
by: Marvin Libson | last post by:
Hi All: I am running DB2 UDB V7.2 with FP11. Platform is Windows 2000. I have created a java UDF and trigger. When I update my database I get the following error: SQL1224N A database...
4
by: Tim.D | last post by:
People, I've ventured into the wonderful world of Stored Procedures. My first experience has been relatively successful however I am stuck on using host variables to specifiy actualy table or...
3
by: claus.hirth | last post by:
Does the term 'host variable' cover a variable locally declared in a SQL-PL stored procedure? I am asking this question in the context of the SELECT INTO statement.
10
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All...
2
by: Frank Swarbrick | last post by:
I'm just learning about embedded SQL, so be gentle... My basic question is, if I use a fixed length host variable for a column defined as VARCHAR, will trailing spaces be removed (or not) upon...
1
by: young | last post by:
Hello all, I tried to do a sqc program with a "SELECT column INTO :host_variable FROM table" statement and got an error SQL4942N="The statement selects an incompatible data type into host...
1
by: Ergates | last post by:
I'm sure I'm just being thick, but I just can't get the following to work. I have loaded an XSD file into an Oracle xmltype table (called xsd_table here). The xsd looks roughly like this: ...
1
by: vineetbindal | last post by:
Hi All, I am new to silverlight and i am following a tutorial. In order to connect to database in silverlight application i need to add a referance to a service. which gives me an error that the...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.