In SQL, use the SUBSTR() function to specify the starting position and length of the character to be replaced, and then use the REPLACE() function to replace the character at the specified position. The syntax is REPLACE(string, start, length, new_string) .
Replace the character at the specified position in SQL
In SQL, you can use the SUBSTR() function and REPLACE( ) function to replace the character at the specified position.
Syntax
REPLACE(string, start, length, new_string)
Parameters
string
: The original character of the character to be replaced string.start
: The starting position of the character to be replaced (counting from 1).length
: The length of the characters to be replaced.new_string
: String used for replacement.Example
Replace the 3 characters starting from the 5th position in the string to "ABC":
SELECT REPLACE('Hello World', 5, 3, 'ABC');
Output:
Hello ABCld
SUBSTR() function
SUBSTR() function can be used to specify the starting position and length of the characters to be replaced:
Syntax
SUBSTR(string, start, length)
Parameters
string
: The original string from which the substring is to be extracted.start
: The starting position of the substring to be extracted (counting from 1).length
: The length of the substring to be extracted.Example
Use the SUBSTR() function to specify the substring to be replaced:
SELECT REPLACE('Hello World', SUBSTR('Hello World', 5, 3), 'ABC');
Output:
Hello ABCld
The above is the detailed content of How to replace characters at specified positions in sql. For more information, please follow other related articles on the PHP Chinese website!