首頁  >  文章  >  資料庫  >  如果'Pos'不在字串的長度範圍內,在函數INSERT(str, Pos, len, newstr)中,會得到什麼結果?

如果'Pos'不在字串的長度範圍內,在函數INSERT(str, Pos, len, newstr)中,會得到什麼結果?

WBOY
WBOY轉載
2023-08-24 13:21:061353瀏覽

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

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)

以上是如果'Pos'不在字串的長度範圍內,在函數INSERT(str, Pos, len, newstr)中,會得到什麼結果?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除