Home > Database > Mysql Tutorial > body text

If 'Pos' is not within the length range of the string, what will be the result in the function INSERT(str, Pos, len, newstr)?

WBOY
Release: 2023-08-24 13:21:06
forward
1391 people have browsed it

如果\'Pos\'不在字符串的长度范围内,在函数INSERT(str, Pos, len, newstr)中,会得到什么结果?

MySQL INSERT() function does not perform the insertion operation when the insertion position is not within the string length range. There are some cases, like when we pass a negative value or 0 (zero) value, or when the value is more than 2 values ​​of the total number of characters in the original string, we can say that 'pos' is not within the string length. It can be understood through the following example:

Example

The following query will not perform the insertion operation because 'pos' is not within the string length range, that is, it is a negative value.

mysql> Select INSERT('Tutorialspoint',-1,4,'.com');
+--------------------------------------+
| INSERT('Tutorialspoint',-1,4,'.com') |
+--------------------------------------+
| Tutorialspoint                       |
+--------------------------------------+
1 row in set (0.00 sec)
Copy after login

The query below will not perform the insertion because 'pos' is not within the length of the string, which is 0 (zero).

mysql> Select INSERT('Tutorialspoint',0,4,'.com');
+-------------------------------------+
| INSERT('Tutorialspoint',0,4,'.com') |
+-------------------------------------+
| Tutorialspoint                      |
+-------------------------------------+
1 row in set (0.00 sec)
Copy after login

The following query will not perform an insertion because 'pos' is not within the string length, i.e. a value exceeding the number of characters in the original string by 2. In the example below, the original string 'Tutorialspoint' has 14 characters and we have given the position value as 16 so no insertion will occur.

mysql> Select INSERT('Tutorialspoint',16,4,'.com');
+--------------------------------------+
| INSERT('Tutorialspoint',16,4,'.com') |
+--------------------------------------+
| Tutorialspoint                       |
+--------------------------------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of If 'Pos' is not within the length range of the string, what will be the result in the function INSERT(str, Pos, len, newstr)?. 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