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

CURSOR Keeps Closing

I wrote a stored procedure that contains some COMMIT logic, but keep
runnign into an odd problem. As soon as the procedure gets to the
COMMIT statement, the CURSOR closes. Here's the procedure:

CREATE PROCEDURE AIM.UPDATEARCHIVERETRIEVALSTATUS ( )
SPECIFIC AIM.UPDATEARCRETSTS
LANGUAGE SQL

P1: BEGIN
DECLARE RECORDCOUNT INTEGER;
DECLARE intLOOPS INTEGER;
DECLARE intImageCount INTEGER;
DECLARE decArchiveRetrievalID DECIMAL (13,0);
DECLARE AT_END int DEFAULT 0;
DECLARE NOT_FOUND CONDITION FOR SQLSTATE '02000';
DECLARE UPDATE_CURSOR CURSOR FOR
SELECT ARCHIVERETRIEVALID FROM AIM.ARCHIVERETRIEVAL WHERE
ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP --AND EXPIRATIONDATE <
DATE(CURRENT TIMESTAMP)
AND STATUSID = 2
--OR SELECT ARCHIVERETRIEVALID FROM AIM.ARCHIVERETRIEVAL WHERE
OR
ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP AND EXPIRATIONDATE IS NULL
AND STATUSID = 2;

DECLARE CONTINUE HANDLER for NOT_FOUND
SET AT_END = 1;

SET intLOOPS = 0;
SET RECORDCOUNT = 0;

OPEN UPDATE_CURSOR;
FETCH_LOOP:
LOOP
FETCH UPDATE_CURSOR INTO decArchiveRetrievalID;
SET intImageCount = (SELECT COUNT(IMAGEFRONT) FROM AIM.AIMRETRIEVEDITEM
WHERE ARCHIVERETRIEVALID = decArchiveRetrievalID
AND LENGTH(IMAGEFRONT) > 0);
IF AT_END = 1 THEN
LEAVE FETCH_LOOP;
ELSEIF intImageCount = (SELECT ITEMCOUNT FROM AIM.ARCHIVERETRIEVAL
WHERE ARCHIVERETRIEVALID = decArchiveRetrievalID) THEN
ITERATE FETCH_LOOP;
END IF;
UPDATE AIM.ArchiveRetrieval SET STATUSID = 3 WHERE ARCHIVERETRIEVALID =
decArchiveRetrievalID;
SET RECORDCOUNT = RECORDCOUNT + 1;
IF RECORDCOUNT = 10 THEN
COMMIT;
SET intLOOPS = intLOOPS + 1;
SET RECORDCOUNT = 0;
END IF;
END LOOP FETCH_LOOP;
CLOSE UPDATE_CURSOR;

CALL AIM.UPDATEAIMRETRIEVALSTATUS_CRON();

END P1

For instance, I know there should be 45 rows updated. The procedure
gets through the first set of 10 updates and then it bombs and gives me
the following error:

A database manager error occurred.[IBM][CLI Driver][DB2/6000] SQL0501N
The cursor specified in a FETCH or CLOSE statement is not open.
SQLSTATE=24501

Can I assume the COMMIT is what's causing it to close the cursor? Is
there any way to address this?

THanks for any help!

Nov 12 '05 #1
2 9446
"ansonee" <an*****@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I wrote a stored procedure that contains some COMMIT logic, but keep
runnign into an odd problem. As soon as the procedure gets to the
COMMIT statement, the CURSOR closes. Here's the procedure:

CREATE PROCEDURE AIM.UPDATEARCHIVERETRIEVALSTATUS ( )
SPECIFIC AIM.UPDATEARCRETSTS
LANGUAGE SQL

P1: BEGIN
DECLARE RECORDCOUNT INTEGER;
DECLARE intLOOPS INTEGER;
DECLARE intImageCount INTEGER;
DECLARE decArchiveRetrievalID DECIMAL (13,0);
DECLARE AT_END int DEFAULT 0;
DECLARE NOT_FOUND CONDITION FOR SQLSTATE '02000';
DECLARE UPDATE_CURSOR CURSOR FOR
SELECT ARCHIVERETRIEVALID FROM AIM.ARCHIVERETRIEVAL WHERE
ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP --AND EXPIRATIONDATE <
DATE(CURRENT TIMESTAMP)
AND STATUSID = 2
--OR SELECT ARCHIVERETRIEVALID FROM AIM.ARCHIVERETRIEVAL WHERE
OR
ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP AND EXPIRATIONDATE IS NULL
AND STATUSID = 2;

DECLARE CONTINUE HANDLER for NOT_FOUND
SET AT_END = 1;

SET intLOOPS = 0;
SET RECORDCOUNT = 0;

OPEN UPDATE_CURSOR;
FETCH_LOOP:
LOOP
FETCH UPDATE_CURSOR INTO decArchiveRetrievalID;
SET intImageCount = (SELECT COUNT(IMAGEFRONT) FROM AIM.AIMRETRIEVEDITEM
WHERE ARCHIVERETRIEVALID = decArchiveRetrievalID
AND LENGTH(IMAGEFRONT) > 0);
IF AT_END = 1 THEN
LEAVE FETCH_LOOP;
ELSEIF intImageCount = (SELECT ITEMCOUNT FROM AIM.ARCHIVERETRIEVAL
WHERE ARCHIVERETRIEVALID = decArchiveRetrievalID) THEN
ITERATE FETCH_LOOP;
END IF;
UPDATE AIM.ArchiveRetrieval SET STATUSID = 3 WHERE ARCHIVERETRIEVALID =
decArchiveRetrievalID;
SET RECORDCOUNT = RECORDCOUNT + 1;
IF RECORDCOUNT = 10 THEN
COMMIT;
SET intLOOPS = intLOOPS + 1;
SET RECORDCOUNT = 0;
END IF;
END LOOP FETCH_LOOP;
CLOSE UPDATE_CURSOR;

CALL AIM.UPDATEAIMRETRIEVALSTATUS_CRON();

END P1

For instance, I know there should be 45 rows updated. The procedure
gets through the first set of 10 updates and then it bombs and gives me
the following error:

A database manager error occurred.[IBM][CLI Driver][DB2/6000] SQL0501N
The cursor specified in a FETCH or CLOSE statement is not open.
SQLSTATE=24501

Can I assume the COMMIT is what's causing it to close the cursor? Is
there any way to address this?

THanks for any help!

Cursor closes at COMMIT unless you use the WITH HOLD option on cursor.
Nov 12 '05 #2
have you tried accomplishing the same task using only SQL, i.e.

UPDATE AIM.ArchiveRetrieval SET STATUSID = 3
WHERE
((ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP --AND EXPIRATIONDATE <
DATE(CURRENT TIMESTAMP)
AND STATUSID = 2)
OR
(ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP AND EXPIRATIONDATE IS NULL
AND STATUSID = 2))
AND
(
(SELECT COUNT(IMAGEFRONT) FROM AIM.AIMRETRIEVEDITEM
WHERE ARCHIVERETRIEVALID = AIM.ArchiveRetrieval.ARCHIVERETRIEVALID
AND LENGTH(IMAGEFRONT) > 0)
<>
(SELECT ITEMCOUNT FROM AIM.ARCHIVERETRIEVAL
WHERE ARCHIVERETRIEVALID = AIM.ArchiveRetrieval.ARCHIVERETRIEVALID )
)

Nov 12 '05 #3

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

Similar topics

1
by: dinesh prasad | last post by:
I'm simply trying to divide each close1 column by 20, then insert that value into the twentydayMA field. The query keeps on running without finishing, even if I'm only using a single page of data....
1
by: ilPostino | last post by:
I'm using this function to load a custom cursor from a .cur file; public static extern IntPtr LoadCursorFromFile(String str); It works great but if I popup a ContextMenu or Control like a...
2
by: Nathan Sokalski | last post by:
I have a section in my ASP.NET code where I have an HTML unordered list. Visual Studio keeps removing the closing list item tags, except for the last list item. In other words, Visual Studio makes...
3
by: Rud | last post by:
I'm still searching for an easy way to implement customized mouse pointers. I've searched in the help text but couldn't get the answer. Do I have to dig into the creation of resource files or is...
5
by: Paul M | last post by:
Hi All, I've been tasked with writing a z/OS C program to read and update a table (DB/2 v8). This Table contains a single row with a single column of data. This program (which will run as a...
10
by: Franky | last post by:
I think I misread a post and understood that if I do: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor there is no need to reset the cursor to Default. So I made all the reset...
2
by: Florian Lindner | last post by:
Hello, I have a function that executes a SQL statement with MySQLdb: def executeSQL(sql, *args): print sql % args cursor = conn.cursor() cursor.execute(sql, args) cursor.close() it's...
1
by: love2livedislife | last post by:
I have a requirement as follows: while executing the procedure for first time i'll open a cursor and read the first row from it and return the value through OUT parameter of procedure without...
1
by: luigidavinci | last post by:
I am using Scriptaculous to achieve a pretty simple and straightforward effect. I need a couple of images and text to fade in and fade out periodically, which I already managed to do it using...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.