DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 20th, 2004, 05:25 PM
anaveens anaveens is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 anaveens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy DB2: How to delete using fetch first

Situation : Need to delete first 10 rows at a time from a set of rows that are returned

Solutions available :
1) Fetch first as part of select subquery
2) Using ROW_NUMBER OVER...some column name
3) Select partial reocrd usign subquery

Analysis : I can't use (3)

Looking for solution for deleting the records using "fetch first N rows only" clause

DELETE FROM TABLE_NAME WHERE COL_NAME IN (SELECT COL_NAME FROM TABLE_NAME FETCH FIRST 'N' ROWS ONLY)

ERROR: db2 => delete * from staff where id in (select id from staff order by id fetch f
irst 1 row only)
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "delete" was found following
"BEGIN-OF-STATEMENT". Expected tokens may include: "SELECT". SQLSTATE=42601

Reply With Quote
  #2  
Old July 21st, 2004, 08:26 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 39 m 5 sec
Reputation Power: 116
I believe the asterisk is not supposed to be there. Try

delete from staff where id in (select id from staff order by id fetch first 1 row only)
__________________
~Nemi

Before posting did you try:
[ Javadocs | Google ]

Reply With Quote
  #3  
Old July 21st, 2004, 09:50 AM
anaveens anaveens is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 anaveens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
DB2: How to delete using fetch first

Yeah, i tried without "*" symbol only...in first place..(typo)


The problem I found is that its availabel only in version higher than 8+ ..so its solved.

By the way, do u knwo how to use Block Cursors for deletion?

Reply With Quote
  #4  
Old July 21st, 2004, 11:25 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 39 m 5 sec
Reputation Power: 116
Nope, sorry.

Reply With Quote
  #5  
Old July 22nd, 2004, 04:07 PM
anaveens anaveens is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 anaveens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Deletion using Cursors

Is there any BEST way to delete set of records at a time using cursors?

DB2 Version = 7.2.5 on AIX
Embedded SQL on C++

Reply With Quote
  #6  
Old January 16th, 2013, 04:43 AM
ascendedcrow ascendedcrow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Pretoria, South Africa
Posts: 3 ascendedcrow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 52 sec
Reputation Power: 0
Send a message via Google Talk to ascendedcrow
Cursor

Try this:

BEGIN NOT ATOMIC
FOR REC AS C1 CURSOR WITH HOLD FOR
SELECT 'TEST' col1,
ROW_NUMBER() OVER() as ROWNUM
FROM TABLE
DO
DELETE FROM TABLE WHERE PKEY = COL1;--
IF MOD(ROWNUM,10000) = 0 THEN commit;--
end if;--
END FOR;--
commit;--
END;


Quote:
Originally Posted by anaveens
Is there any BEST way to delete set of records at a time using cursors?

DB2 Version = 7.2.5 on AIX
Embedded SQL on C++

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > DB2: How to delete using fetch first

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap