473,466 Members | 4,855 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Execute multiple statements in a Procedure

I am new to DB2 and here is my situation.
I have 2 temp tables where I am trying to insert data (from 2 select
statements)

DECLARE v_t1 VARCHAR(50);
DECLARE v_t1 VARCHAR(50);

DECLARE stmt1 STATEMENT;
DECLARE stmt2 STATEMENT;

v_t1 = 'insert into session.t1 select p_key from tab1';
v_t2 = 'insert into session.t2 select c_key from tab2';

PREPARE stmt1 from v_t1;
EXECUTE stmt1;

--This is where it fails
PREPARE stmt2 from v_t2;
EXECUTE stmt2;
This is kind of how my Proc looks. When I go in the debug mode. I pass
the first EXECUTE and the moment it comes to the second one, it fails
and I get this error message...

A database manager error occurred.[IBM][CLI Driver][DB2/6000] SQL0518N
The statement named in the EXECUTE statement is not in a prepared state
or is a SELECT or VALUES statement. SQLSTATE=07003

----------------------

What am I doing wrong? I would really appreciate if someone could help
me out here.
Thanks in advance.

- Nabil

Nov 12 '05 #1
2 6685
Nabil wrote:
I am new to DB2 and here is my situation.
I have 2 temp tables where I am trying to insert data (from 2 select
statements)

DECLARE v_t1 VARCHAR(50);
DECLARE v_t1 VARCHAR(50);

DECLARE stmt1 STATEMENT;
DECLARE stmt2 STATEMENT;

v_t1 = 'insert into session.t1 select p_key from tab1';
v_t2 = 'insert into session.t2 select c_key from tab2';

PREPARE stmt1 from v_t1;
EXECUTE stmt1;

--This is where it fails
PREPARE stmt2 from v_t2;
EXECUTE stmt2;
This is kind of how my Proc looks. When I go in the debug mode. I pass
the first EXECUTE and the moment it comes to the second one, it fails
and I get this error message...

A database manager error occurred.[IBM][CLI Driver][DB2/6000] SQL0518N
The statement named in the EXECUTE statement is not in a prepared state
or is a SELECT or VALUES statement. SQLSTATE=07003

----------------------

What am I doing wrong? I would really appreciate if someone could help
me out here.
Thanks in advance.

- Nabil

Works for me on V8.2.2 (FP9). Obviously you haven't posted the real
source code. So, could it be that you have a typo in one of the PREPARE
statements using the wrong statement name?

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
Hey thanks. That was it. It was a typo error. I really appreciate your
help.

Nabil

Nov 12 '05 #3

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

Similar topics

6
by: Doohan W. | last post by:
Hi, I'm now working with DB2, and I can't find out how to execute the contents of a string Statement, without using a Java/... procedure, only using SQL statements. I know that some SQBDs such...
2
by: Noloader | last post by:
Hello, Access XP, SQL Server 2000 Is it possible to hide a SP under Queries in Access, yet still be able to Execute it from Access? (Similar to hiding Tables, then using Views) We hooked...
7
by: JIM.H. | last post by:
Hello, Is there any difference to between SLQ string in the code and call execute query and call a stored procedure and execute the query that way concerning speed, effectiveness, reliability,...
1
by: andychambers2002 | last post by:
Hi, Should execute() be allowed to execute multiple operations? e.g. from dbi import * conn = connect(database="test") curs = conn.cursor()
1
by: rAinDeEr | last post by:
Hi, I have started using DB2 UDB ESE v8.2 in Linux recently. I have seen a lot of articles on packages, prepare statement, bind and execute statement. I havent got a clear idea. I have...
14
by: technocrat | last post by:
db2 -t -v -f/home.../filename >output_file-name I have a java stored procedure..which has to run the above command...not sure how i can run this command through java.. any suggestions are...
5
by: alingsjtu | last post by:
Hello, every body. When execute dynamic generated multiple OPENQUERY statements (which linkes to DB2) in SQLServer, I always got SQL1040N The maximum number of applications is already connected...
4
by: vertigo262 | last post by:
Is it possible to use to select statements in a stored procedure? I am building a movie rating system, what I am doing is creating a table with movies and individual user ratings. The code...
0
by: David | last post by:
- Are there any peculiarities with using curs.executemany(...) vs. multiple How many times are you calling execute vs a single executemany? The python call overhead will add up for thousands of...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.