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 > To fetch the last row of a cursor's result set

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-02-06, 02:13
Shefu Shefu is offline
Registered User
 
Join Date: Apr 2005
Posts: 127
To fetch the last row of a cursor's result set

Hi all

how could i fetch the last row of a result set returned by a cursor without traversing thru the cursor's result set..

i find some Fetch Last options in DB2 for OS/360. but not able to use it in my environment.. is there any workaround...

My DB2 version : 8.1.3
OS : Windows 2000

regards
Sn

Last edited by Shefu; 02-02-06 at 02:30.
Reply With Quote
  #2 (permalink)  
Old 02-02-06, 02:21
Shefu Shefu is offline
Registered User
 
Join Date: Apr 2005
Posts: 127
I tried to use the following SELECT into statement

Code:
select col1 into var1 from table

this worked fine if the result set returned is of single row..
and this stores a null value ie., '-' in var1 if the query returns multiple rows in the result set.

so i tried to use a cursor with the above select query and in case of multiple rows in the result set of the select query i want the var1 to be assigned the value of the last row in the result set.

hence i asked suggestion to the fetch last row value without traversing the cursor's result set in the above post..

hope this makes my requirement clear..

thanks,
Sn.
Reply With Quote
  #3 (permalink)  
Old 02-02-06, 05:09
ritz ritz is offline
Registered User
 
Join Date: Jan 2005
Posts: 35
Hi Shefu,

You could use "select col1 into var1 from table fetch first 1 row only" to return a single row. In this case the value of only the first row will be returned.

HTH
Ritz
Reply With Quote
  #4 (permalink)  
Old 02-02-06, 08:41
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by Shefu
i asked suggestion to the fetch last row value without traversing the cursor's result set
Order your result set the other way around and fetch the first row.
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