tags:

views:

2221

answers:

2

This question asks about getting a random(ish) sample of records on sqlserver and the answer was to use "TABLESAMPLE", is there an equivalent in Oracle 10?

If there isn't is there a standard way to get a random sample of results from a query set. For example to get 1000 random rows from a query that will return Millions normally.

+4  A: 
SELECT  *
FROM    (
        SELECT  *
        FROM    mytable
        ORDER BY
                dbms_random.value
        )
WHERE rownum <= 1000
Quassnoi
A little slow, but does the job, thank you.
Jeremy French
DBMS_RANDOM is PL/SQL, and there is no pure SQL way in Oracle to generate random numbers. All hail context switch.
Quassnoi
+5  A: 

There is also a special sample clause to select a percentage: http://oracleact.com/papers/sampleclause.html

tuinstoel
This works on a table, but the @op asks for a 'query set', and sample is not applicable for a query set, only for individual tables in a join. +1 for the reference, nevertheless.
Quassnoi
Actually this better suits my needs. Looks like it can be used for multiple tables in oracle 10 as well, but Quassnoi's solution did what I needed and responded in minutes so he keeps the tick :)
Jeremy French