Case-sensitive conversion in MySQL strings

Source: Internet
Author: User

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 ()

 
 
  1. mysql> select lower('DDD');
  2. +--------------+| lower('DDD') |+--------------+|   
  3. ddd |+--------------+mysql> select upper('ddd');  
  4. +--------------+| upper('ddd') |+--------------+| DDD |+--------------+mysql> select lcase('DDD');  
  5. +--------------+| lcase('DDD') |+--------------+| ddd |+--------------+mysql> select ucase('ddd');
  6. +--------------+| 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 ()

 
 
  1. mysql> select concat('.', ltrim(' ddd '), '.');
  2. +----------------------------------+| concat('.', ltrim(' ddd '), '.') 
  3. |+----------------------------------+| .ddd . |+----------------------------------+
  4. mysql> select concat('.', rtrim(' ddd '), '.');
  5. +----------------------------------+| concat('.', rtrim(' ddd '), '.') 
  6. |+----------------------------------+| . ddd. |+----------------------------------+mysql> select concat('.', trim(' ddd '), '.');
  7. +---------------------------------+| 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.

 
 
  1. mysql> select trim(leading '.' from '..ddd..');
    +----------------------------------+| trim(leading '.' from '..ddd..') 
    |+----------------------------------+| ddd.. |+----------------------------------+ 

2. Clear the tail character of the string.

 
 
  1. mysql> select trim(trailing '.' from '..ddd..');
    +-----------------------------------+| trim(trailing '.' from '..ddd..') 
    |+-----------------------------------+| ..ddd |+-----------------------------------+ 

3. Clear the first and end characters of the string.

 
 
  1. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.