Oracle:DBMS_RANDOM.VALUE取随机数.
2011-11-03 16:50 Tracy. 阅读(774) 评论(0) 编辑 收藏 举报两种取随机记录的写法。第二种比较好。
WITH src AS (SELECT COLUMN_VALUE str FROM TABLE (fn_split ('ABDE,EDCE,FEDC', ','))), num AS (SELECT str, ROW_NUMBER () OVER (ORDER BY NULL) rn FROM src), ran AS (SELECT TRUNC (DBMS_RANDOM.VALUE (1, 4)) rand FROM DUAL) SELECT * FROM num WHERE rn = (SELECT rand FROM ran)
SELECT str FROM ( SELECT COLUMN_VALUE str FROM TABLE (fn_split ('ABDE,EDCE,FEDC', ',')) ORDER BY DBMS_RANDOM.VALUE) WHERE ROWNUM = 1
本文来自博客园,作者:Tracy.,转载请注明原文链接:https://www.cnblogs.com/tracy/archive/2011/11/03/2234735.html