Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2002

    Unanswered: determine Cursor length / without FETCH ?????


    I need to retrieve one random tuple from a big set of tuples returned by a
    certain query. So my question is:

    How can I find out the number of tuples returned by cursor, without actually
    FETCHing ALL? (So I can MOVE then to that location and just FETCH 1).


  2. #2
    Join Date
    Nov 2001
    I am not sure if I have understood your problem. Anyway here goes my advice.

    If you want to select a random tupla, first of all you need to know how many of them there are. To achieve this write:

    select count(*) from table where conditions;

    Then get a random number between 1 and the number you got with the previous query. Execute the fetch command inside a loop and stop it when you reach the tupla you got with the random number.

    A faster way is to ensure all tuplas got an unique id from 1 to ..., so when you get the random number, you can select the tupla with that id.

    Hope this helps.

Posting Permissions

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