1

I gave the query:

select dbms_random.value 
  from table;

How do I get the 25% sample?

Ollie
  • 17,058
  • 7
  • 48
  • 59
user1539756
  • 41
  • 1
  • 2
  • 7
  • You can look here as a starting point: http://stackoverflow.com/questions/733652/select-a-random-sample-of-results-from-an-oracle-query – Dave Richardson Jul 20 '12 at 12:35

3 Answers3

5

The select statement allows that.

The sample_clause lets you instruct the database to select from a random sample of data from the table, rather than from the entire table.

Selecting a Sample: Example The following query estimates the number of orders in the orders table:

SELECT COUNT(*) * 10 FROM orders SAMPLE (10);

COUNT(*)*10
-----------
         70

Look here

Alessandro Rossi
  • 2,432
  • 17
  • 24
  • 1
    This answer is not a great format, could you please put detail into the answer as well as the link, it means future users who come across this question do not have to navigate away from SO to get the answer they need. It also mitigates the risk of the link becoming broken over time. – Ollie Jul 20 '12 at 12:53
1
SELECT * FROM (
    SELECT temp.*, COUNT(*) OVER () count_rows
    FROM temp ORDER BY dbms_random.value) 
WHERE rownum <= 0.25 * count_rows;
Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158
user1539756
  • 41
  • 1
  • 2
  • 7
1

Another method:

SELECT * FROM (
  SELECT mytable.*
        ,NTILE(4) OVER (ORDER BY DBMS_RANDOM.value)
         AS quartile
  FROM mytable
  )
WHERE quartile = 1;
Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158