MySQL Tutorial/String Functions/TRIM — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 09:49, 26 мая 2010
Содержание
- 1 If you wanted to trim leading and trailing characters, you would use the keyword BOTH
- 2 SELECT TRIM(LEADING "XXX" FROM "XXXFileName")
- 3 The TRIM() function can trim spaces and characters or groups of characters.
- 4 TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] str)
- 5 TRIM(BOTH "x" FROM "xxxjava2sxxx");
- 6 TRIM(LEADING "x" FROM "xxxhava2sxxx");
- 7 TRIM(TRAILING "xyz" FROM "java2sxxyz");
If you wanted to trim leading and trailing characters, you would use the keyword BOTH
mysql>
mysql>
mysql> SELECT TRIM(BOTH "XXX" FROM "XXXFileNameXXX");
+----------------------------------------+
| TRIM(BOTH "XXX" FROM "XXXFileNameXXX") |
+----------------------------------------+
| FileName |
+----------------------------------------+
1 row in set (0.00 sec)
mysql>
SELECT TRIM(LEADING "XXX" FROM "XXXFileName")
mysql>
mysql> SELECT TRIM(LEADING "XXX" FROM "XXXFileName");
+----------------------------------------+
| TRIM(LEADING "XXX" FROM "XXXFileName") |
+----------------------------------------+
| FileName |
+----------------------------------------+
1 row in set (0.00 sec)
The TRIM() function can trim spaces and characters or groups of characters.
mysql>
mysql>
mysql> SELECT TRIM(TRAILING "XXX" FROM "FileName.XXX");
+------------------------------------------+
| TRIM(TRAILING "XXX" FROM "FileName.XXX") |
+------------------------------------------+
| FileName. |
+------------------------------------------+
1 row in set (0.00 sec)
mysql>
TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] str)
Returns the string str with all remstr prefixes or suffixes removed.
If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed.
remstr is optional and, if not specified, spaces are removed.
mysql>
mysql>
mysql> SELECT TRIM(" sqle ");
+---------------------+
| TRIM(" sqle ") |
+---------------------+
| sqle |
+---------------------+
1 row in set (0.00 sec)
mysql>
TRIM(BOTH "x" FROM "xxxjava2sxxx");
mysql>
mysql>
mysql>
mysql> SELECT TRIM(BOTH "x" FROM "xxxsqlexxx");
+------------------------------------+
| TRIM(BOTH "x" FROM "xxxsqlexxx") |
+------------------------------------+
| sqle |
+------------------------------------+
1 row in set (0.00 sec)
mysql>
TRIM(LEADING "x" FROM "xxxhava2sxxx");
mysql>
mysql> SELECT TRIM(LEADING "x" FROM "xxxhava2sxxx");
+---------------------------------------+
| TRIM(LEADING "x" FROM "xxxhava2sxxx") |
+---------------------------------------+
| hava2sxxx |
+---------------------------------------+
1 row in set (0.01 sec)
mysql>
TRIM(TRAILING "xyz" FROM "java2sxxyz");
mysql>
mysql>
mysql> SELECT TRIM(TRAILING "xyz" FROM "sqlexxyz");
+----------------------------------------+
| TRIM(TRAILING "xyz" FROM "sqlexxyz") |
+----------------------------------------+
| sqlex |
+----------------------------------------+
1 row in set (0.01 sec)
mysql>