Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    127

    Unanswered: 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 03:30.

  2. #2
    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.

  3. #3
    Join Date
    Jan 2005
    Posts
    36
    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

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •