| Author |
Message |
casey.kirkpatrick@gmail.c *nix forums beginner
Joined: 08 Jun 2005
Posts: 20
|
Posted: Tue Feb 22, 2005 10:33 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
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. |
|
| Back to top |
|
 |
andreas.krisor@gmx.net *nix forums beginner
Joined: 18 Feb 2005
Posts: 8
|
Posted: Tue Feb 22, 2005 1:52 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
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 |
|
| Back to top |
|
 |
SteveSutley@cox.net *nix forums beginner
Joined: 21 Feb 2005
Posts: 1
|
Posted: Mon Feb 21, 2005 2:46 am Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
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@gmx.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 |
|
|
| Back to top |
|
 |
Malcolm Dew-Jones *nix forums Guru
Joined: 04 Mar 2005
Posts: 418
|
Posted: Sun Feb 20, 2005 3:45 am Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
andreas.krisor@gmx.net (andreas.krisor@gmx.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. |
|
| Back to top |
|
 |
andreas.krisor@gmx.net *nix forums beginner
Joined: 18 Feb 2005
Posts: 8
|
Posted: Sat Feb 19, 2005 7:53 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
Hi,
this probably works, but unfortunately I don't have the CREATE VIEW
priv in my schema. |
|
| Back to top |
|
 |
andreas.krisor@gmx.net *nix forums beginner
Joined: 18 Feb 2005
Posts: 8
|
Posted: Sat Feb 19, 2005 7:50 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
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 |
|
| Back to top |
|
 |
andreas.krisor@gmx.net *nix forums beginner
Joined: 18 Feb 2005
Posts: 8
|
Posted: Sat Feb 19, 2005 7:44 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
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 |
|
| Back to top |
|
 |
Malcolm Dew-Jones *nix forums Guru
Joined: 04 Mar 2005
Posts: 418
|
Posted: Fri Feb 18, 2005 9:25 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
andreas.krisor@gmx.net (andreas.krisor@gmx.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. |
|
| Back to top |
|
 |
IANAL_VISTA *nix forums Guru
Joined: 23 Apr 2005
Posts: 485
|
Posted: Fri Feb 18, 2005 2:48 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
"andreas.krisor@gmx.net" <andreas.krisor@gmx.net> wrote in
news:1108737915.215801.132860@f14g2000cwb.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; |
|
| Back to top |
|
 |
Volker Hetzer *nix forums Guru Wannabe
Joined: 04 Apr 2005
Posts: 214
|
Posted: Fri Feb 18, 2005 2:29 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
<andreas.krisor@gmx.net> schrieb im Newsbeitrag news:1108737915.215801.132860@f14g2000cwb.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 |
|
| Back to top |
|
 |
andreas.krisor@gmx.net *nix forums beginner
Joined: 18 Feb 2005
Posts: 8
|
Posted: Fri Feb 18, 2005 1:49 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
Hi Norm,
thank you, but still I have a problem (see below).
Greetz,
Andreas |
|
| Back to top |
|
 |
andreas.krisor@gmx.net *nix forums beginner
Joined: 18 Feb 2005
Posts: 8
|
Posted: Fri Feb 18, 2005 1:45 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
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 |
|
| Back to top |
|
 |
IANAL_VISTA *nix forums Guru
Joined: 23 Apr 2005
Posts: 485
|
Posted: Fri Feb 18, 2005 1:40 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
"andreas.krisor@gmx.net" <andreas.krisor@gmx.net> wrote in
news:1108736215.318122.236000@g14g2000cwa.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 |
|
| Back to top |
|
 |
David Aldridge *nix forums beginner
Joined: 03 Feb 2005
Posts: 46
|
Posted: Fri Feb 18, 2005 1:20 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
You can also try the SAMPLE clause in the select statement. SQL
Reference for details |
|
| Back to top |
|
 |
Norman Dunbar *nix forums beginner
Joined: 09 Feb 2005
Posts: 24
|
Posted: Fri Feb 18, 2005 1:16 pm Post subject:
Re: Retrieving a set of randomly chosen records (Oracle 9i)
|
|
|
andreas.krisor@gmx.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. |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|