MySQL INSERT() function does not perform the insertion operation when the insertion position is not within the string length range. There are some cases, like when we pass a negative value or 0 (zero) value, or when the value is more than 2 values of the total number of characters in the original string, we can say that 'pos' is not within the string length. It can be understood through the following example:
The following query will not perform the insertion operation because 'pos' is not within the string length range, that is, it is a negative value.
mysql> Select INSERT('Tutorialspoint',-1,4,'.com'); +--------------------------------------+ | INSERT('Tutorialspoint',-1,4,'.com') | +--------------------------------------+ | Tutorialspoint | +--------------------------------------+ 1 row in set (0.00 sec)
The query below will not perform the insertion because 'pos' is not within the length of the string, which is 0 (zero).
mysql> Select INSERT('Tutorialspoint',0,4,'.com'); +-------------------------------------+ | INSERT('Tutorialspoint',0,4,'.com') | +-------------------------------------+ | Tutorialspoint | +-------------------------------------+ 1 row in set (0.00 sec)
The following query will not perform an insertion because 'pos' is not within the string length, i.e. a value exceeding the number of characters in the original string by 2. In the example below, the original string 'Tutorialspoint' has 14 characters and we have given the position value as 16 so no insertion will occur.
mysql> Select INSERT('Tutorialspoint',16,4,'.com'); +--------------------------------------+ | INSERT('Tutorialspoint',16,4,'.com') | +--------------------------------------+ | Tutorialspoint | +--------------------------------------+ 1 row in set (0.00 sec)
The above is the detailed content of If 'Pos' is not within the length range of the string, what will be the result in the function INSERT(str, Pos, len, newstr)?. For more information, please follow other related articles on the PHP Chinese website!