View previous topic :: View next topic |
Author |
Message |
deepatred Beginner
Joined: 29 Nov 2005 Posts: 19 Topics: 6
|
Posted: Tue Jan 17, 2006 3:18 am Post subject: Deleting using cursor deletes from table or cursor |
|
|
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 |
|
 |
CZerfas Intermediate
Joined: 31 Jan 2003 Posts: 211 Topics: 8
|
Posted: Tue Jan 17, 2006 3:59 am Post subject: |
|
|
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 |
|
 |
deepatred Beginner
Joined: 29 Nov 2005 Posts: 19 Topics: 6
|
Posted: Tue Jan 17, 2006 11:14 pm Post subject: |
|
|
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 |
|
 |
CZerfas Intermediate
Joined: 31 Jan 2003 Posts: 211 Topics: 8
|
Posted: Wed Jan 18, 2006 2:30 am Post subject: |
|
|
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 |
|
 |
deepatred Beginner
Joined: 29 Nov 2005 Posts: 19 Topics: 6
|
Posted: Thu Jan 19, 2006 9:39 pm Post subject: |
|
|
ok, thanks |
|
Back to top |
|
 |
|
|