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 −
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中文網其他相關文章!