473,722 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ 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 6755
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
5391
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 as SQL Server allows it as the exemple bellow shows : EXECUTE 'SELECT * FROM Test' Is there any way to do so with DB2 ?
2
2034
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 up a custom form to accept the input parameters (MS Feature Request!) for the Stored Procedure. We had two problems with MS's
7
3217
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, …? Thanks, Jim.
1
1557
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
2939
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 written a few stored procedures but havent used prepare and execute.
14
11152
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 appreciated..
5
12262
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 to the database. SQLSTATE=57030. Background: I created a linked server to DB2 8.1 database which called GRR_DB2Server. In my stored procedure p_FetchRawData, I need to read some data from this linked server GRR_DB2Server and insert them into
4
6935
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 needs to get a count of the ratings, then the sum of them to get the percentage. I am getting a error Exception Details: System.IndexOutOfRangeException: columncount
0
4080
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 calls. The relevant source code is here if you're interested: http://svn.python.org/projects/python/trunk/Modules/_sqlite/cursor.c
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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 we have to send another system
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.