The INSERT() function adds a substring into another string at a specific position, replacing a set number of characters.
MySQL INSERT Function Syntax
SQL
x
1
INSERT(string, position, number, string2)
MySQL INSERT Function Example
This query attempts to insert 'Dr.'
into the first_name of a doctor, starting at the first character and replacing 0 characters:
SQL
1
1
SELECT INSERT(first_name, 1, 0, 'Dr. ') AS ModifiedName
2
FROM Doctors;
Note: The INSERT() function is not supported in SQLite or TechKubo Playground.
MySQL INSERT Function Parameters
Parameter | Description |
---|---|
string | The original string to be modified |
position | The position where the insertion starts |
number | The number of characters to replace |
string2 | The string to insert |
MySQL INSERT Function Patients Table Example
This query tries to add 'Mr. '
in front of every patient’s last name, replacing 0 characters at position 1:
SQL
1
1
SELECT INSERT(last_name, 1, 0, 'Mr. ') AS ModifiedLastName
2
FROM Patients;
Note: The INSERT() function is not supported in SQLite or TechKubo Playground. Example will not run.
MySQL INSERT Function Notes
- This function is used to insert one string into another at a specific position, replacing a certain number of characters.
- If the start position is past the string’s length, the original string is returned.
- Not supported in SQLite or TechKubo Playground.