• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 658
  • 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
0
pma111
Asked:
pma111
2 Solutions
 
chaitu chaituCommented:
select *
from sometable
where rownum <= 30
0
 
Naveen KumarProduction 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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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