Home >Database >Mysql Tutorial >What happens if the insertion position in the MySQL INSERT() function is out of range?
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 −
The 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)
The query below will not perform insertion because the position of insertion is out of range i.e. 0 (zero).
mysql> Select INSERT('Virat', 0,5,'Kohli'); +------------------------------+ | INSERT('Virat', 0,5,'Kohli') | +------------------------------+ | Virat | +------------------------------+ 1 row in set (0.00 sec)
The query below will not perform the insertion operation because the insertion position is out of range, i.e. a value of 2 that exceeds the number of characters in the original string. In the example below, the original string 'Virat' has 5 characters and the position value we have given is 7, so the insertion will not happen.
mysql> Select INSERT('Virat', 7,5,'Kohli'); +------------------------------+ | INSERT('Virat', 7,5,'Kohli') | +------------------------------+ | Virat | +------------------------------+ 1 row in set (0.00 sec)
The above is the detailed content of What happens if the insertion position in the MySQL INSERT() function is out of range?. For more information, please follow other related articles on the PHP Chinese website!