Detailed example of mysql similar to oracle rownum writing

Detailed example of mysql similar to oracle rownum writing

Rownum is a unique way of writing in Oracle. In Oracle, rownum can be used to retrieve the first piece of data or to limit the number of batches to be written when writing data in batches.

How to write the first data in mysql

SELECT * FROM t order by id LIMIT 1;

How to write the first data in oracle

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

OK, the above is a comparison of the writing methods of MySQL and Oracle to get the first data, but this is only one usage of rownum. Rownum can also be used to write data in batches.

Write 10,000 records to table t in batches:

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

Oracle original writing:

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

SQL rewritten by mysql:

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);

The above is all the knowledge points introduced this time. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of the misunderstanding between MySQL and Oracle
  • Implementation of SpringBoot multi-database connection (mysql+oracle)
  • Detailed explanation of the solution for real-time synchronization from MySQL to Oracle
  • Example of creating table statements for user Scott in MySQL version of Oracle
  • Description of the default transaction isolation level of mysql and oracle
  • Description of the correspondence between MyBatis JdbcType and Oracle and MySql data types
  • Summary of the differences between MySQL and Oracle (comparison of functional performance, selection, SQL when using them, etc.)
  • A brief discussion on the differences between the three major databases: Mysql, SqlServer, and Oracle
  • Problems and solutions when replacing Oracle with MySQL

<<:  jQuery implements employee management registration page

>>:  How to install Linux system (Redhat8) and virtual machine network configuration in VMware

Recommend

How to use Xtrabackup to back up and restore MySQL

Table of contents 1. Backup 1.1 Fully prepared 1....

Various methods to implement the prompt function of text box in html

You can use the attribute in HTML5 <input="...

Steps for Django to connect to local MySQL database (pycharm)

Step 1: Change DATABASES in setting.py # Configur...

Detailed explanation of JavaScript's built-in Date object

Table of contents Date Object Creating a Date Obj...

New settings for text and fonts in CSS3

Text Shadow text-shadow: horizontal offset vertic...

Markup Language - List

Standardized design solutions - markup languages ...

Detailed explanation of creating, calling and managing MySQL stored procedures

Table of contents Introduction to stored procedur...

How to implement email alert in zabbix

Implemented according to the online tutorial. zab...

W3C Tutorial (3): W3C HTML Activities

HTML is a hybrid language used for publishing on ...

Reasons and solutions for MySQL selecting the wrong index

In MySQL, you can specify multiple indexes for a ...

How to set static IP for Ubuntu 18.04 Server

1. Background Netplan is a new command-line netwo...

Implementation of dynamic rem for mobile layout

Dynamic rem 1. First, let’s introduce the current...