Get the App
SLTechnology News&Howtos  ›  Database  › 

Detailed explanation of mysql similar to oracle rownum writing example

Shulou Source: shulou.com Published: 2022-06-01 04:10:52 09月28日 Update

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

Tags: Data writing ten thousand articles content original just that is quantity time limit knowledge knowledge points support examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi Huawei Microsoft Shulou Information