This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a requirement to randomly select a string from a resultset. How do I do it ?
I have a resultset which selects 2 strings from Oracle database.
Like this: Select a,b from table a where xxx
Lets say my query gives me 5 record sets. For each transaction I want to retrieve results randomly, like if first transaction output is 1 recordset then second should be 2 recordset or 3 record set etc[random outputs] Can I achieve this in Java/JDBC ?
I know I can get Random results using dbms_random package in Oracle, but doing this I have to do two queries.
Jeanne, I meant row, which means I misunderstood the question in the first place, but as you said this this approach can be used in both scenarios.
Atul, here are the steps to do it. 1. Use the Math.random() method to get a random value. 2. get the result set. 3. if you dont already know the number of rows then use last(),getRow() on your result set object to get the number of available number of rows. and then calculate a random row number with the help of the random number calculated at 1. 4. use absolute(with number calulated at 3)
your cursor is at a random row.
author & internet detective