dbTalk Databases Forums  

Retrieving a set of randomly chosen records (Oracle 9i)

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Retrieving a set of randomly chosen records (Oracle 9i) in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
andreas.krisor@gmx.net
 
Posts: n/a

Default Re: Retrieving a set of randomly chosen records (Oracle 9i) - 02-19-2005 , 02:50 PM






Hi Malcolm,

I have at the moment no possibility to try your suggestion but I think
the ROWNUM refers to the result set of a query, so a full table scan is
used for this statement which reduces the performance dramatically and
therefore wouldn't be applicable.

Am I right?

Greetz,
Andreas


Reply With Quote
  #12  
Old   
andreas.krisor@gmx.net
 
Posts: n/a

Default Re: Retrieving a set of randomly chosen records (Oracle 9i) - 02-19-2005 , 02:53 PM






Hi,

this probably works, but unfortunately I don't have the CREATE VIEW
priv in my schema.


Reply With Quote
  #13  
Old   
Malcolm Dew-Jones
 
Posts: n/a

Default Re: Retrieving a set of randomly chosen records (Oracle 9i) - 02-19-2005 , 10:45 PM



andreas.krisor (AT) gmx (DOT) net (andreas.krisor (AT) gmx (DOT) net) wrote:
: Hi Malcolm,

: I have at the moment no possibility to try your suggestion but I think
: the ROWNUM refers to the result set of a query, so a full table scan is
: used for this statement which reduces the performance dramatically and
: therefore wouldn't be applicable.

: Am I right?

maybe, I don't know for sure

However my suggestion was less than optimal, not sure what I was thinking.
I haven't tested the code but I'm pretty sure you don't need to select
from a select, simply

select * from table where rownum modulus whatever


That could in theory be optimized at the remote end to retrieve only a
some of the rows.

As for a full table scan (which I also responded to just above) if you
want any kind of randomish sample then surely you will have to scan the
whole table - the only issue is whether the remote end can do the scan so
as to reduce the amount of data that must be sent.



--

This space not for rent.

Reply With Quote
  #14  
Old   
SteveSutley@cox.net
 
Posts: n/a

Default Re: Retrieving a set of randomly chosen records (Oracle 9i) - 02-20-2005 , 09:46 PM



Andreas,

The SAMPLE is best, but if it is not good for you, you can try MOD.
This example returns 1 row from every 100 rows.

SELECT columnA, columnB
FROM your_table
GROUP BY columnA, columnB
HAVING MOD(MAX(ROWNUM), 100) = 1

The result set is automatically ordered. The same rows are picked each
time (if the table is not changed).

HTH

Steve


andreas.krisor (AT) gmx (DOT) net wrote:
Quote:
Hi,

I need to analyze the data of very large tables (over 10 million
records). Therefore I want to retrieve a set of randomly chosen
records
(about 50,000).

Question: Exists a predefined function in Oracle 9i, which fetches a
certain part (e.g. 1%) of the rows of a table?

Hint: Because I need to get all of the data in a random order and not
in the way the rows are arranged in the table I cannot work with
SELECT
* from xxx WHERE ROWNUM < 50001.
But maybe the ROWID can be utilized to fetch a random sample of the
rows?

King regards,

Andreas


Reply With Quote
  #15  
Old   
andreas.krisor@gmx.net
 
Posts: n/a

Default Re: Retrieving a set of randomly chosen records (Oracle 9i) - 02-22-2005 , 08:52 AM



Hi Steve,

thank you for your suggestion but the statement runs about half an
hour, so it doesn't really work for me.

Greetz,
Andreas


Reply With Quote
  #16  
Old   
casey.kirkpatrick@gmail.com
 
Posts: n/a

Default Re: Retrieving a set of randomly chosen records (Oracle 9i) - 02-22-2005 , 05:33 PM



select * from table where DBMS_UTILITY.get_hash_value(ROWID ||
to_char(sysdate,'HH:MI:SS'),1,100) = 1

The "100" can be tweaked to give more or fewer rows.


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.