oracle關於取數的小知識

2021-08-14 13:25:31 字數 1127 閱讀 8856

--隨機取100條資料從pucentp表中;

select * from (select * from pucentp order

by trunc(dbms_random.random())) where

1=1and rownum<= 100;

select * from (select * from pucentp order

by trunc(dbms_random.value())) where

1=1and rownum<= 100;

dbms_random.value()比dbms_random.random()提取資料速度要快,一般用前者;

--從pucentp表中抽取20%的資料然後從20%的資料中隨機抽取5條資料;

select * from pucentp sample (20) where rownum <= 5;

select * from pucentp sample block (20) where rownum <= 5;

select * from pucentp sample (20) seed(3) where rownum <= 5;

select * from pucentp sample block (20) seed(11) where rownum <= 5;

select to_char(currentdate,'yyyy') currentyear,count(id) sss from  pucship where ( to_number(to_char(sysdate,'yyyy')) - to_number(to_char(currentdate,'yyyy')) )  <= 4

group

by to_char(currentdate,'yyyy') order

by to_number(to_char(currentdate,'yyyy')) asc;

--currentdate為表中已經存在的日期字段,然後根據當前年份從你表中(匹配)近5年的資料

Oracle 取隨機數

1 從表中隨機取記錄 select from select from staff order by dbms random.random where rownum 4 表示從staff表中隨機取3條記錄 2 產生隨機數 select dbms random.random from dual 產生乙個...

Oracle取隨機數

1 從表中隨機取記錄 select from select from staff order by dbms random.random where rownum 4 表示從staff表中隨機取3條記錄 2 產生隨機數 select dbms random.random from dual 產生乙個...

oracle取隨機數

1 從表中隨機取記錄 select from select from staff order by dbms random.random where rownum 4 表示從staff表中隨機取3條記錄 2 產生隨機數 select dbms random.random from dual 產生乙個...