首頁  >  文章  >  資料庫  >  如果 MySQL INSERT() 函數中的插入位置超出範圍,會發生什麼情況?

如果 MySQL INSERT() 函數中的插入位置超出範圍,會發生什麼情況?

WBOY
WBOY轉載
2023-08-23 20:13:031228瀏覽

如果 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#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刪除