MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Deleting using cursor deletes from table or cursor

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
deepatred
Beginner


Joined: 29 Nov 2005
Posts: 19
Topics: 6

PostPosted: Tue Jan 17, 2006 3:18 am    Post subject: Deleting using cursor deletes from table or cursor Reply with quote

Hi,

When DELETE using a cursor is done, does it delete record from cursor or the actual table?
DELETE FROM table-name WHERE CURRENT OF cursor-name

if it deletes from actual table, is there a way by which we can delete a record from cursor only that does not affect table.

An immediate reply would be of much help.

Thanks,
Back to top
View user's profile Send private message
CZerfas
Intermediate


Joined: 31 Jan 2003
Posts: 211
Topics: 8

PostPosted: Tue Jan 17, 2006 3:59 am    Post subject: Reply with quote

You mean you want to exclude rows from the answer set of your query? Since SQL is a set oriented language, you have to code predicates in the WHERE clause to achieve that.

See also the threads dealing with eliminating duplicate rows; in DB2 this is not a trivia.

regards
Christian
Back to top
View user's profile Send private message
deepatred
Beginner


Joined: 29 Nov 2005
Posts: 19
Topics: 6

PostPosted: Tue Jan 17, 2006 11:14 pm    Post subject: Reply with quote

Hi,

My understanding is if in a DELETE command WHERE clause we specify current record of CURSOR then it deletes that record from the Actual table not locally from cursor.

But if we have used ORDER BY clause then cursor is not deletable, what does CURSOR is not deletable means?
Does it mean that it can not delete from actual table?

After opening the cursor is it possible to delete records from cursor since it is a temporary result set?

Thanks
Back to top
View user's profile Send private message
CZerfas
Intermediate


Joined: 31 Jan 2003
Posts: 211
Topics: 8

PostPosted: Wed Jan 18, 2006 2:30 am    Post subject: Reply with quote

If you understand the concept of a cursor as a "pointer to data rows", then using this cursor to delete rows is only possible, if the cursor points currently to a row in the regular table space.

If you use the ORDER BY clause, all the rows of the answer set have to be fetched into the DB2 sort pool and sorted there. With the first FETCH issued from your program with this cursor, you are no longer "pointing" to a data row, but to an area in the DB2 sort pool.

Deleting there makes no sense at all.

regards
Christian
Back to top
View user's profile Send private message
deepatred
Beginner


Joined: 29 Nov 2005
Posts: 19
Topics: 6

PostPosted: Thu Jan 19, 2006 9:39 pm    Post subject: Reply with quote

ok, thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group