• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 661
  • Last Modified:

select xyz records from an oracle table

is there an easy way within oracle (sql*plus) to run a select clause to only select say a sample of 30 rows per database table.

i.e. select (sample of 30)  * (all fields)
from mytable
2 Solutions
chaitu chaituCommented:
select *
from sometable
where rownum <= 30
Naveen KumarProduction Manager / Application Support ManagerCommented:
select * from your_table
where rownum < 31;

This will give you the 30 records
To see the number of the row use:

select rownum, a.*
from mytable a
where rownum < 31
slightwv (䄆 Netminder) Commented:
Even though you already selected an answer to this, you asked for a 'sample' of data.  The accepted answers return the first 30 rows you select.  This really isn't a sample.

There is a SAMPLE clause in sqlplus that you pass a percentage.

There is also this trick (still uses rownum but against a random order):
select * from
( select * from some_table  order by dbms_random.value)
where rownum<=30
Naveen KumarProduction Manager / Application Support ManagerCommented:
my understanding was that a random sample set of records was not requested to be output each time the query runs otherwise i would have suggested the use of the dbms_random package stuff. Thanks,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now