dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Apr 21, 2020

Understanding INSERT in MySQL

MySQL provides many overridden functions of INSERT. Let us see one of them below.

This function has the syntax as specified. INSERT(str, pos, len, newStr) where str - string pos - position len - length newStr - new string

Query:

SELECT INSERT('Terminator', 4, 10, 'MIN') AS INSERT_OVRDN;

This will replace the text MIN starting from position 4 until the next 10 positions and hence the text 'ator' which are beyond the length of 'MIN' are still replaced with empty chars. Output:

+--------------+
| INSERT_OVRDN |
+--------------+
| TerMIN       |
+--------------+

Query:

SELECT INSERT('Terminator', 4, 3, 'MIN') AS INSERT_OVRDN;

Here, argument 3 specifies that only 3 positions needs to be replaced and hence the text 'ator' is retained.

Output:

+--------------+
| INSERT_OVRDN |
+--------------+
| TerMINator   |
+--------------+ 
M S Sridhar
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date