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

数据库数据库 2023-08-31 03:43:18 702
摘要: MySQLINSERT()functionperformsnoinsertionifthepositionofinsertionisoutofrange.Thepositionofinsertioncanbeoutofrangeinthecasewhenwepassanegativeor0(zero)valueortheva...

如果 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() 函数中的插入位置超出范围,会发生什么情况?的详细内容,更多请关注其它相关文章!