Oracle中的随机剔除数据等

dbms_random.value :该函数用来产生一个介于0和1之间随机数,查询结果随机排序是它的一种用法。

取出0-1之间的随机数: select dbms_random.value from dual;
取出0到任意范围的随机数: select dbms_random.value100 from dual;
如果不想要小数点后面部分:select TRUNC(dbms_random.value
100) from dual;
查询结果随机排列:select * from emp order by dbms_random.value;
随机查询出表中指定条数据: select *
from (select * from emp order by dbms_random.value)
where rownum<=5;
随机查询出表中指定百分比的数据:
select *
from ( select * from emp order by dbms_random.value )
where rownum<=(select count(1)/10 from emp);
删除表中数据,要求保留随机的10%数据:
delete from test where id not in(
select t.id
from (
select * from test order by dbms_random.value
) t
where rownum<=(select count(1)/10 from test)
);

转:https://blog.csdn.net/fengyuan1314/article/details/84155104

Oracle中的随机剔除数据等

上一篇:mysql启动报错---Starting MySQL.. ERROR! The server quit without updating PID file


下一篇:MySQL服务无法启动 报错 Can't init tc log