Solved

select xyz records from an oracle table

Posted on 2014-02-18
5
619 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
history tablespace temp usage 2 30
Consolidating oracle query results to a single line 8 52
Powershell script 13 51
selective queries 7 21
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to take different types of Oracle backups using RMAN.

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now