MySQL is the most popular Relational Database Management System and one of the best RDBMS(Relational Database Management System) applications in WEB applications.

CONCAT()

CONCAT(str1,str2,…) The string concatenation () function returns multiple concatenated strings, for example:

SELECT CONCAT('MySQL'.'String'.'function') AS str; / / equivalent to theSELECT 'MySQL' 'String' 'function' AS str;
str           |
--------------+MySQL | string functionsCopy the code

If any argument in this function is NULL, the result is NULL. Such as:

SELECT CONCAT('MySQL'.NULL.'function') AS str;
str|
---+
   |
Copy the code

If you enable SQL mode PIPES_AS_CONCAT, MySQL the Boolean or operator (| |) can also be used for the connection string. CONCAT_WS (separator, str1 str2,…). The separator function concatenates multiple strings using the specified separator, returning NULL if the separator is NULL. Such as:

SELECT CONCAT_WS(The '-'.'MySQL'.NULL.'function') AS str1,
       CONCAT_WS(NULL.'MySQL'.'String'.'function') AS str2;
str1       |str2|
-----------+----+MySQL - function | |Copy the code

LENGTH()

The CHAR_LENGTH(STR) and CHARACTER_LENGTH(STR) functions are used to return the character length of a string. Such as:

SELECT CHAR_LENGTH('MySQL string function ') AS len1, CHARACTER_LENGTH('MySQL string function ') AS len2;
len1|len2|
----+----+10 | |Copy the code

The LENGTH(STR) and OCTET_LENGTH(STR) functions are used to return the LENGTH of a string in bytes, for example:

SELECT LENGTH('MySQL string function ') AS len1, OCTET_LENGTH('MySQL string function ') AS len2;
len1|len2|
----+----+20 20 | |Copy the code

The BIT_LENGTH(STR) function returns the bit length of a string, for example:

SELECT BIT_LENGTH('MySQL string function ') AS len; len| ---+ 160|Copy the code

LOWER()

The LOWER(STR) and LCASE(STR) functions are used to convert strings to lowercase, for example:

SELECT LOWER('MySQL string function ') AS str1, LCASE('MySQL string function ') AS str2;
str1          |str2          |
--------------+--------------+Mysql | | mysql string string function functionCopy the code

The MySQL case conversion function does not support binary strings. It can be converted to non-binary strings and processed later. Such as:

SELECT LOWER(BINARY 'MySQL string function ') AS str1, LOWER(CONVERT(BINARY 'MySQL string function ' USING utf8)) AS str2;
str1               |str2          |
-------------------+--------------+MySQLa c such ¦ a ¸ squared a 1/2 level æ ° | | mysql string functionsCopy the code

UPPER()

The UPPER(STR) and UCASE(STR) functions are used to convert strings to uppercase, for example:

SELECT UPPER('MySQL string function ') AS str1, UCASE('MySQL string function ') AS str2;
str1          |str2          |
--------------+--------------+MYSQL | | MYSQL string string function functionCopy the code

TRIM()

TRIM ([[BOTH | LEADING | TRAILING] regexStr FROM] STR) function is used to delete the string STR/left/right on BOTH sides all string substring after regexStr, regexStr defaults to space. Such as:

SELECT TRIM('MySQL string function') AS str1, TRIM(TRAILING  The '-' FROM '--MySQL string function --') AS str2;
str1          |str2          |
--------------+--------------+MySQL | string functions| - MySQL string function
Copy the code

REVERSE()

The REVERSE(STR) function is used to REVERSE the order of characters in the string STR. Such as:

SELECT REVERSE('Shanghai tap Water comes from the sea') ='Shanghai tap Water comes from the sea' AS str;
str |
----+1 |Copy the code