首页  >  文章  >  数据库  >  如果 MySQL INSERT() 函数中的插入位置超出范围,会发生什么情况?

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

WBOY
WBOY转载
2023-08-23 20:13:031229浏览

如果 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)

下面的查询不会执行插入操作,因为插入位置超出范围,即0(零)。

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

下面的查询不会执行插入操作,因为插入位置超出范围,即超过原始字符串中字符数量的值2。在下面的示例中,原始字符串'Virat'有5个字符,我们给出的位置值是7,因此不会发生插入。

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

以上是如果 MySQL INSERT() 函数中的插入位置超出范围,会发生什么情况?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除