Skip to main content
Version: V1.0.0

INSERT

Declaration

INSERT (str1,pos,len,str2)

Description

Returns the string str1 with the substring starting at position pos and having length len replaced by str2. If pos exceeds the length of the string, the original string is returned. If len is greater than the length of str2, the replacement starts at position pos. If any argument is NULL, the result is NULL. This function supports multibyte characters.

  • str1 and str2 must be strings, and pos and len must be integers. If any argument is NULL, the result is NULL.

  • Characters in str1 and str2 are treated as a byte stream.

  • If pos is negative or greater than the length of str1, str1 is returned.

  • If len is less than 0 or greater than the length of str1, the result is the combination of the substring from the beginning of str1 to position pos and str2.

Examples

SELECT INSERT('Quadratic',-2,100,'What'), INSERT('Quadratic',7,3,'What'),
INSERT('Quadratic',-1,3,'What'), INSERT('Quadratic',10,3,'What'), INSERT('Quadratic',5,-1,''),
INSERT('Quadratic',7,-1,'What')\G
*************************** 1. row ***************************
INSERT('Quadratic',-2,100,'What'): Quadratic
INSERT('Quadratic',7,3,'What'): QuadraWhat
INSERT('Quadratic',-1,3,'What'): Quadratic
INSERT('Quadratic',10,3,'What'): Quadratic
INSERT('Quadratic',5,-1,''): Quad
INSERT('Quadratic',7,-1,'What'): QuadraWhat
1 row in set (0.001 sec)