473,408 Members | 1,907 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,408 software developers and data experts.

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**@herber-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 3252
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**@herber-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#Antispam@mapsitnA#it4profit.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
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...
1
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,...
8
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...
2
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...
5
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...
5
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...
2
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! ...
7
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...
5
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...
11
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...
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: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.