Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of mysql similar to oracle rownum writing example

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Rownum is a unique way of writing in oracle. Rownum can be used in oracle to take the first piece of data, or to write data in batches within a time limit and to specify the number of writes in batches.

Mysql takes the first piece of data to write

SELECT * FROM t order by id LIMIT 1

Oracle takes the first piece of data to write

SELECT * FROM t where rownum = 1 order by id

Ok, above is the comparison of how mysql and oracle take the first piece of data, but this is only one use of rownum, and rownum can also be used to write data in batches.

Write 10,000 pieces of data in batches to table t:

Insert into t (id,date) select sys_guid (), sysdate from dual connect by rownum

SQL after mysql is rewritten:

SELECT * FROM (SELECT tb.*, @ rownum: = @ rownum + 1 AS rownum FROM (SELECT id, NAME FROM t) tb, (SELECT @ rownum: = 0) r) AS t WHERE rownum

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report