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
LVL 3
pma111Asked:
Who is Participating?
 
chaitu chaituConnect With a Mentor Commented:
select *
from sometable
where rownum <= 30
0
 
Naveen KumarConnect With a Mentor Production Manager / Application Support ManagerCommented:
select * from your_table
where rownum < 31;

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

select rownum, a.*
from mytable a
where rownum < 31
0
 
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
0
 
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,
0
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.

All Courses

From novice to tech pro — start learning today.