Mysql method to remove a string: 1. Intercept the string from the left, the code is [left(str, length)]; 2. Intercept the string from the right, the code is [right(str, length)]; 3. Intercept the string, the code is [substring(str, pos)].
Mysql method to remove a string:
When using mysql, string interception is often performed. Replace, take substrings, etc. The specific introduction is as follows:
1. Intercept the string from the left
left(str, length) Description: left (intercepted field, intercepted length)
Example:
select left('charfunction', 5) as result from dual;
Output: charf
2. Intercept the string from the right
right(str, length) Description: right(intercepted field, intercepted length)
Example:
select right('charfunction',5) as result from dual;
Output: ction
3. Intercept the string. There are two situations here, namely interception from the beginning and interception from the middle.
substring(str, pos) Description: substring (field to be intercepted, starting from which number to intercept)
substring(str, pos, length) substring (field to be intercepted, starting from which number to intercept, length to be intercepted)
Example:
select substring('charfunction', 5) as result from dual; 输出:unction
select substring('charfunction',5,5) as result from dual; 输出:uncti
(Note: If the number of digits is a negative number such as -5, it is the length from the last digit to the end of the string or interception)
4. Replacement related Character
replace (str, old, new) replaces the old string in str with the new string
Example:
select replace ('charfunction','n','WW') as result from dual; 输出: charfuWWctioWW
UpdateMultiple related free learning recommendations: mysql tutorial(Video)
The above is the detailed content of How to remove a string in mysql. For more information, please follow other related articles on the PHP Chinese website!