Application and precautions of MySQL string functions

Source: Internet
Author: User

The following articles mainly describe the actual application of MySQL string functions and the actual operation code. At the same time, this article also describes the actual application of MySQL string functions, the following describes some important things worth your attention.

 
 
  1. CHARSET(str)  

Returns the string character set.

 
 
  1. CONCAT (string2 [,… ])  

Do not use the connection string in the MySQL string function.

 
 
  1. mysql> select concat('a','b');  
  2. +-----------------+  
  3. | concat('a','b') |  
  4. +-----------------+  
  5. | ab |  
  6. +-----------------+  
  7. 1 row in set (0.03 sec)  
  8. mysql> select 'a'||'b';  
  9. +----------+  
  10. | 'a'||'b' |  
  11. +----------+  
  12. | 0 |  
  13. +----------+  
  14. 1 row in set, 2 warnings (0.00 sec)  

INSTR (string, substring) // returns the position of the first occurrence of the substring in the string. If no position exists, 0 is returned.

LCASE (string2) // converts it to lowercase

LEFT (string2, length) // get the length from the LEFT of string2

LENGTH (string) // string LENGTH

LOAD_FILE (file_name) // read content from the file

LOCATE (substring, string [, start_position])

// Same as INSTR, but the start position can be specified

LPAD (string2, length, pad) // repeat pad to start with string until the string length

Is length

LTRIM (string2) // remove leading Spaces

REPEAT (string2, count) // REPEAT count times

REPLACE (str, search_str, replace_str)

// Replace search_str with replace_str in str

RPAD (string2, length, pad) // use pad after str until length

RTRIM (string2) // remove backend Spaces

STRCMP (string1, string2) // compare the size of two strings by character,

SUBSTRING (str, position [, length])

// Start from the position of str and take the length characters

Note: When processing strings in mysql, the default subscript of the first character is 1, that is, the position must be greater than or equal to 1.

 
 
  1. mysql> select substring('abcd',0,2);  
  2. +-----------------------+  
  3. | substring('abcd',0,2) |  
  4. +-----------------------+  
  5. | |  
  6. +-----------------------+  
  7. 1 row in set (0.06 sec)  
  8. mysql> select substring('abcd',1,2);  
  9. +-----------------------+  
  10. | substring('abcd',1,2) |  
  11. +-----------------------+  
  12. | ab |  
  13. +-----------------------+  
  14. 1 row in set (0.00 sec)  
  15. TRIM([[BOTH|LEADING|TRAILING] [padding] FROM]string2)  

Removes specified characters from a specified position.

UCASE (string2) // converts to uppercase

RIGHT (string2, length) // gets the last length character of string2

SPACE (count) // generate count Spaces

The above content is an introduction to MySQL string functions, and I hope you will get some benefits.

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.