亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

mysql類(lèi)似oracle rownum寫(xiě)法實(shí)例詳解

 更新時(shí)間:2019年09月06日 08:13:31   作者:smileNicky  
在本篇文章里小編給大家分享的是關(guān)于mysql類(lèi)似oracle rownum寫(xiě)法以及相關(guān)實(shí)例內(nèi)容,需要的朋友們可以學(xué)習(xí)下。

rownum是oracle才有的寫(xiě)法,rownum在oracle中可以用于取第一條數(shù)據(jù),或者批量寫(xiě)數(shù)據(jù)時(shí)限定批量寫(xiě)的數(shù)量等

mysql取第一條數(shù)據(jù)寫(xiě)法

SELECT * FROM t order by id LIMIT 1;

oracle取第一條數(shù)據(jù)寫(xiě)法

SELECT * FROM t where rownum =1 order by id;

ok,上面是mysql和oracle取第一條數(shù)據(jù)的寫(xiě)法對(duì)比,不過(guò)這只是rownum的一種用法,rownum還可以用于批量寫(xiě)數(shù)據(jù)

往t表批量寫(xiě)一萬(wàn)條數(shù)據(jù):

 insert into t(id,date) select sys_guid(),sysdate from dual connect by rownum<=10000;

oracle原版寫(xiě)法:

select * from (select id,name from t) where rownum <![CDATA[<=]]> to_number(num);

mysql改寫(xiě)后的SQL:

SELECT 
 * 
FROM
 (SELECT 
  tb.*,
  @rownum := @rownum + 1 AS rownum 
 FROM
  (SELECT 
   id,
   NAME 
  FROM
   t) tb,
  (SELECT 
   @rownum := 0) r) AS t 
WHERE rownum <= CAST(num AS SIGNED INTEGER) ;

以上就是本次介紹的全部知識(shí)點(diǎn)內(nèi)容,感謝大家對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論