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)