General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 12th, 2003, 02:50 PM
bash3_cmc bash3_cmc is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 3 bash3_cmc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post random sql selections in oracle.

These are the 3 ways i've found to do random selections in oracle. If there's a better way... SOMEONE tell me.

1) NO WHERE CLAUSE, 10%:
select * from my_table sample(10)

The other two aren't so pretty...

2) WHERE CLAUSE, no order clause. When using ado, you can do a recordcount * 10% and just print that many records:

select my_table.*
from my_table
[WHERE CLAUSE]
order by mod(DBMS_RANDOM.Random,50)+50

3) WHERE CLAUSE, order clause. Then, either through an outer query or when running through a loop, just print the records that have RANDOM less than 10

select mod(DBMS_RANDOM.Random,50)+50 as RANDOM,
my_table.*
from my_table
[WHERE CLAUSE]
order by page,revision

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > random sql selections in oracle.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway