If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Cursor not working

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 02-10-10, 07:21
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I think this error is raised when you try to execute the update after reaching the end of result set. Add a condition handler for NOT FOUND that would exit the loop. There are examples of how it's done in the manual. Something like:
Code:
declare done int default 0;
...
declare condition handler for not found set done=1;
...
loop
  fetch ...;
  if done = 1 leave;
  ...
end loop

Last edited by n_i; 02-10-10 at 07:28.
Reply With Quote
  #17 (permalink)  
Old 02-10-10, 09:08
jeunne0000 jeunne0000 is offline
Registered User
 
Join Date: Feb 2010
Posts: 11
Thanks n_i!

I have one last question.

Is it possible to have like this in WHERE clause?

===============================
update table1
set body = 'blah'
where id in (select id from table2)
and current of c1;

===============================

C1 is the cursor name.
Thanks again!



[-]
Reply With Quote
  #18 (permalink)  
Old 02-10-10, 10:04
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by jeunne0000 View Post

Is it possible to have like this in WHERE clause?
The answer to your question is in the manual. You can use a construct similar to
Code:
if exists (select ...)
 update .. where current ...
end if
Reply With Quote
  #19 (permalink)  
Old 02-11-10, 03:04
jeunne0000 jeunne0000 is offline
Registered User
 
Join Date: Feb 2010
Posts: 11
Update

Thanks again n_i!

I've madesome changes to my script. Now it is giving me this error

================================================== ========

SQL0501N The cursor specified in a FETCH or CLOSE statement is not open.

================================================== ========


What I would like to do is like this:

================================================== ========
begin
declare c1 cursor...
for read only
open c1
loop...
fetch c1 into v_id, v_name;
call session.UPDATE_TBL(v_id, v_name); (is this possible?)
end loop...
close c1;
end@
================================================== ========


session.UPDATE_TBL procedure is just a one UPDATE statement.


Please help. Many Thanks again!


[-]

Last edited by jeunne0000; 02-11-10 at 05:06.
Reply With Quote
  #20 (permalink)  
Old 02-11-10, 07:14
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by jeunne0000 View Post

session.UPDATE_TBL procedure is just a one UPDATE statement.
Are you sure about that? Did you sneak a commit in there too, by chance?
Reply With Quote
  #21 (permalink)  
Old 02-12-10, 01:58
jeunne0000 jeunne0000 is offline
Registered User
 
Join Date: Feb 2010
Posts: 11
Oh! the session.UPDATE_TBL has 2 update statements with commit. So is that a problem and causes the FETCH and CLOSE error?

Many thanks again for the prompt reply. I really really appreciate it!

[-]
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On