分类: Oracle
2006-11-02 16:44:34
SELECT *
FROM (SELECT EMPNO, ENAME FROM SCOTT.EMP ORDER BY DBMS_RANDOM.VALUE)
WHERE ROWNUM <3> 注:dbms_random包需要手工安装,位于$ORACLE_HOME/rdbms/admin/dbmsrand.sql
dbms_random.value(100,200)可以产生100到200范围的随机数
取排序后的前3条记录:
SELECT *
FROM (SELECT EMPNO, ENAME, rownum rn FROM SCOTT.EMP ORDER BY 1)
WHERE rn 取排序后的第4-6条记录:
SELECT *
FROM (SELECT EMPNO, ENAME, rownum rn FROM SCOTT.EMP ORDER BY 1)
WHERE rn between 4 and 6;
11.13 随机产生N个字符串
select dbms_random.string('A',10) from dual;