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 > Oracle > determine Cursor length / without FETCH ?????

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-21-02, 11:09
commageneus commageneus is offline
Registered User
 
Join Date: Feb 2002
Location: iceland
Posts: 15
determine Cursor length / without FETCH ?????

Hello,

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).

Thanks,
Reply With Quote
  #2 (permalink)  
Old 02-22-02, 12:29
pepe pepe is offline
Junior Member
 
Join Date: Nov 2001
Posts: 3
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.
Reply With Quote
Reply

Thread Tools
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