Last active
March 28, 2017 06:10
-
-
Save Philosoft/41a30fe00ca34757f4349411e5e05a2a to your computer and use it in GitHub Desktop.
replace first occurence of substring in string mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @string = 'this is TEST string with AA replace and An Answer'; | |
SELECT @string as actual_string, | |
CONCAT( | |
REPLACE( | |
LEFT( | |
@string, | |
INSTR(@string, 'TEST') + LENGTH('TEST') - 1 | |
), | |
'TEST', | |
'WTF' | |
), | |
SUBSTRING( | |
@string, | |
INSTR(@string, 'TEST') + LENGTH('TEST') | |
) | |
) as new_string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based on http://stackoverflow.com/a/12123560.
now it can correctly replace occurences longer then 1 char