Solved

select xyz records from an oracle table

Posted on 2014-02-18
5
630 Views
Last Modified: 2014-02-18
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
Comment
Question by:pma111
5 Comments
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 250 total points
ID: 39866984
select *
from sometable
where rownum <= 30
0
 
LVL 28

Assisted Solution

by:Naveen Kumar
Naveen Kumar earned 250 total points
ID: 39866987
select * from your_table
where rownum < 31;

This will give you the 30 records
0
 
LVL 1

Expert Comment

by:Lacca
ID: 39867014
To see the number of the row use:

select rownum, a.*
from mytable a
where rownum < 31
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39867296
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
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 39869127
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some very basic things about SQL Server filegroups.
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question