在 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