MySQL character function

Source: Internet
Author: User

1.concat

Select  as  from String_test;

Concat is to concatenate multiple strings together, where you can specify a delimiter (in fact, the string '-' is output to a false separation effect), as follows:

Select concat (first_name,'-' as from String_test;

2.concat_ws

Select concat_ws ('-' as from String_test;

Note: The Concat_ws delimiter is in the first parameter, what is it different from concat? As follows:

Select concat ("|", "A", "B", "C");

With CONCAT_WS can make each word between the existence of separators, to achieve a true separation effect, we look at Concat:

Select concat ("|", "A", "B", "C");

3.format ()

Select Format (19986.78,1);

Format accepts two parameters, the first parameter represents the number to be formatted, and the second parameter represents the number of digits holding the decimal point, where a valid number is retained by rounding.

Select Format (19986.78,2);

3.lower ()

Select Lower ('MYSQL');

The lower () function converts the string to lowercase, and the above code executes the following result:

3.upper ()

Effect contrary to lower

4.left ()

Gets the character to the left of the string, accepts two parameters, the first parameter is the parent string to get, and the second parameter is the length of the fetch, as follows:

Select  Left ('mysql',2);

The function above means: Get a string of length 2 from the left side of MySQL.

5.right ()

Gets the string to the right, as with left.

6.length ()

Gets the length of the string

Select Length ('mysql');

7.ltrim ()

Remove leading spaces

8.rtrim ()

Delete subsequent spaces

9.trim ()

Remove leading and trailing spaces

If a string is such a ===> "??? MySQL???? "

So how do you delete a leading question mark and a subsequent question mark? As follows:

To delete a leading question mark:

Select  from "??? MySQL???? ");

Leading means the leading meaning.

Delete subsequent question marks:

Select  from "??? MySQL???? ");

Delete all question marks:

Select  from "??? MySQL???? ");

MySQL character function

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.