INSERT

2024-06-28 05:30:31  Updated

Syntax

INSERT(str1,pos,len,str2)

Purpose

INSERT() returns the str1 string, which starts from pos. Substrings with a length of len are replaced with str2. If pos exceeds the string length, the original string is returned. If len is greater than the length of other strings, the substring starting from the position pos is replaced. If any argument is NULL, the return value is NULL. This function supports multi-byte characters.

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

  • The characters in str1 and str2 are considered byte streams.

  • If pos is a negative value or exceeds the length of str1, str1 is returned.

  • When len is less than 0 or exceeds the length of str1, a string that combines str1 from the beginning to pos and str2 is returned.

Examples

obclient> 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

Contact Us