在 INSERT(str, Pos, len, newstr) 函数中,如果 'Pos' 超出字符串长度会发生什么?
如果插入位置不在字符串长度范围内,MySQL INSERT() 函数将不会执行任何插入操作。例如,当我们传递负值或 0(零)值,或者当值超出原始字符串中字符总数加 2 时,我们可以说 'pos' 超出了字符串长度。可以通过以下示例来理解:
示例
下面的查询将不会执行任何插入操作,因为 'pos' 超出了字符串长度,即为负值。
mysql> Select INSERT('Tutorialspoint',-1,4,'.com');
+--------------------------------------+
| INSERT('Tutorialspoint',-1,4,'.com') |
+--------------------------------------+
| Tutorialspoint |
+--------------------------------------+
1 row in set (0.00 sec)下面的查询将不会执行任何插入操作,因为 'pos' 超出了字符串长度,即为 0(零)。
mysql> Select INSERT('Tutorialspoint',0,4,'.com');
+-------------------------------------+
| INSERT('Tutorialspoint',0,4,'.com') |
+-------------------------------------+
| Tutorialspoint |
+-------------------------------------+
1 row in set (0.00 sec)下面的查询将不会执行任何插入操作,因为 'pos' 超出了字符串长度,即超出原始字符串中字符总数加 2。在下面的示例中,原始字符串 'Tutorialspoint' 包含 14 个字符,而我们提供的插入位置值为 16,因此不会发生插入操作。
mysql> Select INSERT('Tutorialspoint',16,4,'.com');
+--------------------------------------+
| INSERT('Tutorialspoint',16,4,'.com') |
+--------------------------------------+
| Tutorialspoint |
+--------------------------------------+
1 row in set (0.00 sec)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP