Home > Database > Mysql Tutorial > What happens if the insertion position in the MySQL INSERT() function is out of range?

What happens if the insertion position in the MySQL INSERT() function is out of range?

WBOY
Release: 2023-08-23 20:13:03
forward
1360 people have browsed it

如果 MySQL INSERT() 函数中的插入位置超出范围,会发生什么情况?

MySQL INSERT() function performs no insertion if the position of insertion is out of range. The position of insertion can be out of range in the case when we pass a negative or 0( zero) value or the value goes beyond the value of a total number of characters in an original string by 2. It can be understood with the help of the following example −

Example

The query below will perform no insertion because the position of insertion is out of range i.e. a negative value.

mysql> Select INSERT('Virat', -1,5,'Kohli');
+-------------------------------+
| INSERT('Virat', -1,5,'Kohli') |
+-------------------------------+
| Virat                         |
+-------------------------------+
1 row in set (0.00 sec)
Copy after login

The query below will not perform insertion because the position of insertion is out of range i.e. 0 (zero).

mysql> Select INSERT('Virat', 0,5,'Kohli');
+------------------------------+
| INSERT('Virat', 0,5,'Kohli') |
+------------------------------+
| Virat                        |
+------------------------------+
1 row in set (0.00 sec)
Copy after login

The query below will not perform the insertion operation because the insertion position is out of range, i.e. a value of 2 that exceeds the number of characters in the original string. In the example below, the original string 'Virat' has 5 characters and the position value we have given is 7, so the insertion will not happen.

mysql> Select INSERT('Virat', 7,5,'Kohli');
+------------------------------+
| INSERT('Virat', 7,5,'Kohli') |
+------------------------------+
| Virat                        |
+------------------------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of What happens if the insertion position in the MySQL INSERT() function is out of range?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template