MySQL string function

Source: Internet
Author: User

The first position of a string is labeled 1

    • ASCII (STR): Returns the ASCII code value of the leftmost character
    • CONV (N, From_base, to_base): Converts a number between different cardinality, returns a string number of number N, or null if any argument is null. If To_base is a negative number, it is considered to be a signed count.
      Mysql> Select CONV (' a ', 2);1010mysql> Select CONV (' 6E ', 8);172mysql> Select CONV (-17, 10,-18); ' -H '
    • BIN (N): Returns a binary string representation of N, equivalent to CONV (n, 10, 2).
    • OCT (N)
    • HEX (N)
    • CHAR (N1, N2, ...): Converts the argument to an integer and returns it as a string, where the argument is equivalent to the ASCII code and returns the corresponding character.
      Mysql> Select CHAR (77, 121, 83, 81, ' 76 '); ' MySQL '
  • CONCAT (str1, str2, ...): The connection string, and the numeric parameter is converted to the corresponding character.
  • LENGTH (str)
  • Octet_length (str)
  • Character_length (str): Returns the length of a string
  • LOCATE (substr, str): Returns 0 if not found, note that the subscript starts at 1
  • INSTR (str, substr): Opposite to the locate () parameter
  • Lpad (str, Len, PADSTR): Returns the string str, left with PADSTR fill to know len length
    Mysql> Select Lpad (' 1234 ', 5, ' AB '); A1234 '
  • Rpad (str, Len, PADSTR)
  • Left (str, len): Returns the leftmost Len character
  • Right (str, len)
  • MID (str, POS, len): Returns the string of Len at the beginning of Str from the POS position
  • SUBSTRING (str, POS)
  • Substring_index (str, Delim, count): Returns the left or right substring by the number of left-to-right count delimiter Delim, which returns to the left, count is negative, and the right
    Mysql> Select Substring_index (' www.mysql.com ', '. ', 2); ' Www.mysql '
  • LTRIM (str): Returns a string that removes the preceding space
  • RTRIM (str)
  • TRIM ([Leading | TRAILING | BOTH] [remstr] from str): Delete Front | back | Both sides of the substring remstr, default to BOTH, remstr default to Spaces
    Select TRIM (TRAILING ' abc ' from ' 1234abc '); ' 1234 '
  • Space (N): Returns a string consisting of N spaces
  • REPLACE (str, FROM_STR, TO_STR)
  • REPEAT (str, count)
  • REVERSE (str)
  • INSERT (str, POS, Len, newstr): STR is replaced by NEWSTR with a substring of length Len starting from the POS
  • ELT (n, str1, str2, STR3, ...): if n = 1, return str1, n = 2, return str2 ...
  • FIELD (str, str1, str2, STR3, ...): Returns the first number of STR
  • Find_in_set (str, strlist): If STR is in Strlist, a number is returned indicating that STR appears in the first few
    Mysql> Select Find_in_set (' B ', ' a,b,c,d '); 2
  • Make_set (Bits, str1, str2, ...): Returned by str1 ... Some of these are grouped into strings, separated by ', ' forms, bits binary corresponding bits if 1 then select the str,str1 corresponding bit 0,str2 corresponding bit 1 ...
    Mysql> Select Make_set (1 | 2, ' hello ', ' nice ', ' world '); Hello,nice ' mysql> make_set (4 | 2, ' hello ', ' nice ', ' world '); Nice,world ' mysql> SELECT make_set (0, ' a ', ' B ', ' C ');
    • Export_set (Bits, on, off, [separator, [number_of_bits]]): A bit similar to the bits,bits binary number 1 with on, 0 bits with off, the default separator is ', ', Bits less than number_of_bits are used to complete the back
      Mysql> Select Export_set (8 | 2 | 1, ' a ', ' B ', ', ', ' 6 '); a,a,b,a,b,b
    • LOWER (str): Return lowercase
    • UPPER (str)
    • Load_file (file_name): reads the file and returns the contents of the file as a string content, the file must be on the server, and must have access rights.
    • MySQL automatically transforms the numbers and strings when necessary
      Mysql> Select 1 + ' 1 ';2mysql> select CONCAT (2, ' Test '); ' 2 Test '

MySQL string function

Related Article

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.