开发者

random selection of string in java

I am working on a project using jsp and servlets and oracle 10g in access layer. I have created a sequence on a field in my database which gets auto incremented when a record is inserted. The sequence is stored as a string in database.开发者_StackOverflow Now i have to select randomly few of these sequence elements using servlets.

How can i do it?


A simple google search led me to the following query:

SELECT column FROM
   ( SELECT column FROM table
     ORDER BY dbms_random.value )
WHERE rownum <= 10

This will select 10 randow table.column values (in Oracle).

If you need more columns:

SELECT * FROM
   ( SELECT column1, column2, column3 FROM table
     ORDER BY dbms_random.value )
WHERE rownum <= 10

Just use JDBC to execute this query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜