The following articles mainly describe the practical application of MySQL strings, including case-sensitive conversion of MySQL database strings and how to clear spaces at the beginning and end of a string, the following is a detailed description. I hope you will get something.
MySQL string case-sensitive Conversion
DeMySQL string case-sensitive conversion functions include lower (), uppper (), lcase (), and ucase ()
- mysql> select lower('DDD');
- +--------------+| lower('DDD') |+--------------+|
- ddd |+--------------+mysql> select upper('ddd');
- +--------------+| upper('ddd') |+--------------+| DDD |+--------------+mysql> select lcase('DDD');
- +--------------+| lcase('DDD') |+--------------+| ddd |+--------------+mysql> select ucase('ddd');
- +--------------+| ucase('ddd') |+--------------+| DDD |+--------------+
In general, I select lower () and upper () to convert string case, because it is compatible with functions in other databases.
Removes spaces at the beginning and end of a string.
In MySQL, there are three spaces at the beginning and end of the MySQL string: ltrim (), rtrim (), trim ()
- mysql> select concat('.', ltrim(' ddd '), '.');
- +----------------------------------+| concat('.', ltrim(' ddd '), '.')
- |+----------------------------------+| .ddd . |+----------------------------------+
- mysql> select concat('.', rtrim(' ddd '), '.');
- +----------------------------------+| concat('.', rtrim(' ddd '), '.')
- |+----------------------------------+| . ddd. |+----------------------------------+mysql> select concat('.', trim(' ddd '), '.');
- +---------------------------------+| concat('.', trim(' ddd '), '.') |+---------------------------------+| .ddd. |+---------------------------------+
The trim string function in MySQL is really powerful. It not only removes spaces at the beginning and end of a string, but also removes any specified characters. Ltrim (), rtrim () is only a subset of its functions. Let's take a look at the complete syntax of the trim function:
1. trim ([{both | leading | trailing} [remstr] from] str) 2. trim ([remstr from] str)
1. Clear the MySQL string header characters.
- mysql> select trim(leading '.' from '..ddd..');
+----------------------------------+| trim(leading '.' from '..ddd..')
|+----------------------------------+| ddd.. |+----------------------------------+
2. Clear the tail character of the string.
- mysql> select trim(trailing '.' from '..ddd..');
+-----------------------------------+| trim(trailing '.' from '..ddd..')
|+-----------------------------------+| ..ddd |+-----------------------------------+
3. Clear the first and end characters of the string.
- mysql> select trim(both '.' from '..ddd..');
+-------------------------------+| trim(both '.' from '..ddd..')
|+-------------------------------+| ddd |+-------------------------------+
mysql> select trim('.' from '..ddd..');+--------------------------+|
trim('.' from '..ddd..') |+--------------------------+| ddd |+--------------------------+trim()
By default, spaces at the beginning and end of the MySQL string are cleared.