Wednesday, May 5, 2010

Return a Random Rows from Table by SQL

Hi all,

While working on sample quiz application on ADF i got requirement to return the random questions from the table for every quiz user. For this I used DBMS_RANDOM package

I feel it would be cool to share it.

Example: Return Random 30 rows from the table


select mycolumn from
( SELECT mycolumn 
    FROM MyTable
ORDER BY 
dbms_random.value )
where rownum <= 30;

Cheers,
Baig

3 comments:

  1. I have the search Panel in above. i have Edit button in panel collection.It should be disable when there is no row in the table and it should enable as soon as the rows reflect after searching.

    ReplyDelete
  2. Hi Priya,

    Your comments is out of topic best way is to email me using contact me page.

    Anyways, You can check the Disabled property of the button based on Rows in the iterator.

    I will try to post a simple example

    ZB

    ReplyDelete
  3. I was thinking of complex logic to select random viewrow based on random number generation for a Online Test Application.. Thanks for Sharing..

    ReplyDelete