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
  #1  
Old   
Norman Dunbar
 
Posts: n/a

Default Re: Retrieving a set of randomly chosen records (Oracle 9i) - 02-18-2005 , 07:38 AM






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?

Hi Andreas,

try this :

SELECT <stuff>
FROM <table>
SAMPLE(1);

The number in brackets (1) is the percentage of the table you want. You
will usually get a different sample on each execution. You cannot
guarantee that you will always get the same number of rows in the sample
though.


Cheers,
Norm.


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

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






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
  #3  
Old   
David Aldridge
 
Posts: n/a

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



You can also try the SAMPLE clause in the select statement. SQL
Reference for details


Reply With Quote
  #4  
Old   
IANAL_VISTA
 
Posts: n/a

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



"andreas.krisor (AT) gmx (DOT) net" <andreas.krisor (AT) gmx (DOT) net> wrote in
news:1108736215.318122.236000 (AT) g14g2000cwa (DOT) googlegroups.com:

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


Go lookup the keyword "SAMPLE" as part of the SELECT statement


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

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



Hi David,

thank you for this hint, it works partly:

my SELECT-statements refer to tables via a db-link and using SAMPLE
results in an error.

Do you know how I can use SAMPLE with db-links?

Thanks,
Andreas


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

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



Hi Norm,

thank you, but still I have a problem (see below).

Greetz,
Andreas


Reply With Quote
  #7  
Old   
Volker Hetzer
 
Posts: n/a

Default Re: Retrieving a set of randomly chosen records (Oracle 9i) - 02-18-2005 , 09:29 AM




<andreas.krisor (AT) gmx (DOT) net> schrieb im Newsbeitrag news:1108737915.215801.132860 (AT) f14g2000cwb (DOT) googlegroups.com...
Quote:
Hi David,

thank you for this hint, it works partly:

my SELECT-statements refer to tables via a db-link and using SAMPLE
results in an error.

Do you know how I can use SAMPLE with db-links?
Is the link to another oracle db?

Greetings!
Volker


Reply With Quote
  #8  
Old   
IANAL_VISTA
 
Posts: n/a

Default Re: Retrieving a set of randomly chosen records (Oracle 9i) - 02-18-2005 , 09:48 AM



"andreas.krisor (AT) gmx (DOT) net" <andreas.krisor (AT) gmx (DOT) net> wrote in
news:1108737915.215801.132860 (AT) f14g2000cwb (DOT) googlegroups.com:

Quote:
Hi David,

thank you for this hint, it works partly:

my SELECT-statements refer to tables via a db-link and using SAMPLE
results in an error.

Do you know how I can use SAMPLE with db-links?

I can't say that I've tried this, but does it work to create a VIEW
in the remote DB which contains the SAMPLE clause?

SELECT * FROM REMOTE_VIEW@OTHER_DB;


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

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



andreas.krisor (AT) gmx (DOT) net (andreas.krisor (AT) gmx (DOT) net) wrote:
: 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?

why not select every nth row? Not exactly random, but it will select rows
throughout the entire table, which would probably make it representative.

I can't seem to lookup the modulus function to check my syntax, but
something like the following


select * from
( select *,rownum the_rownum from the_table)
)
where modulus(the_rownum,200)=1


You could use a RAND function if it existed to do a similar selection, but
I don't see such a function in my index.

--

This space not for rent.

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

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



Hi Voker,

yes, it refers to another oracle-instance. Is there a difference
between the communication between 2 Oracle DB and an Oracle DB and for
example a DB2 DB?

Greetz,
Andreas


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.