Mysql string processing function packing

Source: Internet
Author: User
Mysql string processing functions ???????? The following are some of the methods used to sort MySql string functions, which are listed for reference only. 1. Invalid Data replacement function: replace (str, from_str, to_str )??????? After the query, it is found that some illegal data exists in the Database, which makes it very ugly. when the data is stored in the database, only the leading and trailing spaces are checked.

How to sort Mysql string processing functions? ??????? The following are some of the methods used to sort MySql string functions, which are listed for reference only. 1. Invalid Data replacement function: replace (str, from_str, to_str )??????? After the query, it is found that some illegal data exists in the Database, which makes it very ugly. when the data is stored in the database, only the leading and trailing spaces are checked.

Sort Mysql string processing functions

?

??????? The following are some of the methods used to sort MySql string functions, which are listed for reference only.

1,Invalid Data replacement


Function:Replace (str, from_str, to_str)
??????? After the query, it is found that some illegal data exists in the Database, which makes it very ugly. when the data is stored in the database, only the leading and trailing spaces are checked. No more strict space removal is performed, and only post-processing can be performed.

        update table set cname = replace(cname,' ','');        update table set cname = replace(cname,' ','');

?

??????? Some fields look like spaces, but they are not actually spaces. This field may be in full-width or other format. Copy the field and paste it into the replacement file.

?

2,Query Result field connection
??????? Function 1:Concat (str1, str2, str3)
??????? Function 2:Concat_ws (splitstr, str1, str2, str3)
??????? Function 3:Group_concat (str)

?

Function 1Concat (str1, str2, str3)
??????? Simple, just concatenate the columns or strings and use them.

?

Function 2Concat_ws (splitstr, str1, str2, str3)?
??????? Concatenate str1, str2, and str3 with splitstr as the separator and return the result.

?

Function 3?Group_concat (str)?
??????? Manual Description: This function returns a string with a non-NULL value from a group of connections.
??????? It is abstract and hard to understand.

??????? Group_concat () calculates which rows belong to the same group and displays the columns belonging to the same group. The columns to be returned are determined by the function parameter (that is, the field name. The group must have a standard, that is, grouping based on the columns specified by group.

1. Test statement,
????????

select province,group_concat(name) from city group by province;

??????? Hebei ??? Baoding, Shijiazhuang, Handan, Xingtai
??????? Beijing ??? Beijing
????????

select group_concat(name) from city;

??????? Baoding, Shijiazhuang, Handan, Xingtai, Beijing

?

Function 4SubString_index (str, indexstr, index)
??????? A string truncation function. The second parameter is a specified character, and the third parameter is the number of occurrences of the character.
????????

select sum(substring_index("0.124M",'M',1)) from dual;

??????? The returned result is 0.124.

?

?

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.