473,756 Members | 6,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Stored Procedure Question

I've a question regarding DB2 SQL Stored Procedures
(DB2 V8.1.4 on Suse Linux).

It seems not to be possible to use the 'where current of <cursor>'
syntax in conjunction with dynamically prepared SQL statements.

When I execute the simple stored procedure (sourcecode see below),
DB2 raises the following error message at the 2nd PREPARE statement:

SQL0504N The cursor "C_STAFF" is not defined. SQLSTATE=34000

The stored procedure provided below is only an example to reproduce
the error. The real stored procedure needs dynamic SQL, so changing
to static SQL is not a solution.

I did not find anything in the documentation about that. To be honest,
the DB2 documentation is horrible, at least regarding SQL stored
procedures.

Any input is greatly appreciated.
Thank you.
CREATE PROCEDURE tmp3()

SPECIFIC tmp3
LANGUAGE SQL

t3: BEGIN

DECLARE v_sql VARCHAR(256);
DECLARE v_id SMALLINT;
DECLARE v_name VARCHAR(9);
DECLARE v_not_found SMALLINT DEFAULT 0;
DECLARE v_stmt1 STATEMENT;
DECLARE v_stmt2 STATEMENT;
DECLARE c_staff CURSOR FOR v_stmt1;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET v_not_found = 1;

SET v_sql = 'SELECT id,name FROM db2inst1.staff FOR UPDATE';
PREPARE v_stmt1 FROM v_sql;

SET v_sql = 'DELETE FROM db2inst1.staff WHERE CURRENT OF c_staff';
--The next PREPARE raises SQL error SQL0504N
PREPARE v_stmt2 FROM v_sql;

OPEN c_staff;
FETCH FROM c_staff INTO v_id, v_name;

WHILE (v_not_found = 0)
DO

EXECUTE v_stmt2;
FETCH FROM c_staff INTO v_id, v_name;

END WHILE;

END t3@

--
IT-Consulting Herber
Email: <mailto:er**@he rber-consulting.de>
Mobile: +49 177 2276895
*************** *************** *************** **
Download the IFMX Database-Monitor for free at:
http://www.herber-consulting.de/BusyBee
*************** *************** *************** **
Nov 12 '05 #1
5 3289
I'm guessing: Try the prepare after the open.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #2
I already tried this, but it doesn't help.
The error message is the same.
Any other ideas ?

Thank you.

Serge Rielau wrote:
I'm guessing: Try the prepare after the open.

Cheers
Serge


--
IT-Consulting Herber
Email: <mailto:er**@he rber-consulting.de>
Mobile: +49 177 2276895
*************** *************** *************** **
Download the IFMX Database-Monitor for free at:
http://www.herber-consulting.de/BusyBee
*************** *************** *************** **
Nov 12 '05 #3
I can't say about version 8, but in ver 7.2 sql-sp converter into C not
used declared cursor name. It's simply assign names CURSx, where x started
from 2.
In you case try change to '... CURRENT OF CURS2'

Andy
Nov 12 '05 #4
Yes, indeed I checked the generated Esql/C File (*.sqc)
and the cursor is named 'curs4'.

If I use that cursor name, it works.
However I'm not sure how reliable this method is and
from my point of view the stored procedure behaviour
should be considered a bug.

Anyway, thank you very much for this hint.
andreyp#Antispa m@mapsitnA#it4p rofit.com wrote:
I can't say about version 8, but in ver 7.2 sql-sp converter into C not
used declared cursor name. It's simply assign names CURSx, where x started
from 2.
In you case try change to '... CURRENT OF CURS2'

Andy


--
IT-Consulting Herber
Mobile: +49 177 2276895
*************** *************** *************** **
Download the IFMX Database-Monitor for free at:
http://www.herber-consulting.de/BusyBee
*************** *************** *************** **
Nov 12 '05 #5
Eric,

I forwarded your example to the SQL PL developers.
The way it works is definitely not the way it should work.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #6

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

Similar topics

3
2485
by: Ryan.Chowdhury | last post by:
This is a general question regarding the use of view and stored procedures. I'm fairly new to databases and SQL. I've created a SQL database using an Access Data Project ("ADP") and I'm satified with the table structure. I've moved on to building some front ends for our users. I'm running into situations where I want subreports to be built from queries that are dependent on the values in other controls. I've played with stored...
1
2572
by: Raquel | last post by:
Have a question on the Stored procedure method code generated by DB2 development center for Java stored procedures. Suppose I have a requirement to return the resultset consisting of FIRSTNME, LASTNAME of all employees belonging to a particular department, following is the stored procedure method code generated by "DB2 development center": public static void sproc3mtd ( String workdept, String firstnme,
8
7944
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have created a temporary database with a tables space. Verified that DECLARE GLOBAL TEMPORARY TABLE TEMP (A INTEGER); INSERT INTO SESSION.TEMP VALUES(10); SELECT A FROM SESSION.TEMP; works from a query tool.
2
9244
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
5
2141
by: Rhino | last post by:
This question relates to DB2 Version 6 on OS/390. Can a (COBOL) stored procedure on this platform do file I/O, i.e. write to a sequential file? I am trying to debug a stored procedure. As far as I know, DB2 stored procedures cannot do terminal I/O on any operating system but I know that (Java) stored procedures in Windows/Linux/Unix can write to files and I have done this many times.
5
1727
by: Andy G | last post by:
I have a registration page that captures 75% of the users data. After they enter that info they are redirected to one of two pages depending on how they answered a question on the registation page. My question is would it be better to store all of the fields(15 or so) from the first page in session variables and reference them from the next page and run ONE stored procedure OR would it be better to run a stored procedure the first page...
2
1434
by: singlal | last post by:
Hi, my question was not getting any attention because it moved to 2nd page; so posting it again. Sorry for any inconvenience but I need to get it resolved fast. Need your help! **************************************************************************************************** Original Question: -------------------- Has anyone called a COBOL subroutine using COBOL CALL from a COBOL/DB2
7
9714
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason for this being to stop the user thinking the application has frozen when in fact it is just waiting for a long SP to complete. Another reason for doing it like this is that I also have had a problem in the past where the SP takes longer than the...
5
2361
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored Procedures with a data reader to add various parameters. However, if I have a stored procedure such as CREATE usp_SelectfromJobNumbers (@par1 datatype, @par2 datatype, @par3 datatype)
11
3443
by: peter | last post by:
I am trying to get a SQL stored procedure to use user maintained MQT implicitly which raises questions on when they are used or not used. In theory you would expect the stored procedure to pick up the MQT at the time it is bound on the creation of the static SQL. This raises the question on how you stop it or start it using a MQT as there is no option on the bind. What happens when it is rebound? What happens if the plan is made invalid...
0
9487
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
10069
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
9904
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
9884
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,...
1
7285
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
5168
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
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.