(1) MySQL replace function
Syntax: replace (object,search,replace)
Replaces all occurrences of search in object with replace
Case:
The code is as follows |
Copy Code |
1 Update ' News ' Set ' content ' =replace (' content ', ', ', '); |
Clear the spaces in the content field in the news table
(2) MySQL trim function
Full format: TRIM ([{BOTH | Leading | Trailing} [REMSTR] from] str)
Simplified format: TRIM ([remstr from] str)
The following examples illustrate:
The code is as follows |
Copy Code |
1 mysql> SELECT TRIM (' phpernote '); 2-> ' Phpernote ' 1 mysql> SELECT TRIM (leading ' x ' from ' xxxphpernotexxx '); 2-> ' phpernotexxx ' 1 mysql> SELECT TRIM (BOTH ' x ' from ' xxxphpernotexxx '); 2-> ' Phpernote ' 1 mysql> SELECT TRIM (trailing ' xyz ' from ' phpernotexxyz '); |
To remove the left space function in MySQL:
The code is as follows |
Copy Code |
LTRIM (str) Returns the string str with leading space characters removed. |
The following is a code fragment:
code is as follows |
copy code |
mysql> SELECT LTRIM (' Barbar '); -> ' Barbar ' This function is multi-byte safe. Remove the right space function in MySQL: RTRIM (str) Returns the string str with trailing spaces characters removed. The following code fragment: mysql> SELECT RTRIM (' barbar '); -> ' barbar ' This function is Multi-Byte safe. |