Common string Functions in MySQL (1/3)

Source: Internet
Author: User

ASCII (STR)
Returns the ASCII code value of the leftmost character of the string str. If Str is an empty string, returns 0. If STR is NULL, returns NULL.

MySQL Tutorial > select ASCII (' 2 ');
-> 50
Mysql> Select ASCII (2);
-> 50
Mysql> Select ASCII (' DX ');
->


You can also see the Ord () function.

Ord (str)
If the string str leftmost character is a multibyte character, by using the format (the *256+ (the second byte ASCII code)) [*256+third byte ASCII code ...] Returns the ASCII code value of the character to return the multibyte character code. If the leftmost character is not a multibyte character. Returns the same value returned with the ASCII () function.

mysql> Select Ord (' 2 ');
->



Conv (n,from_base,to_base)
Transforms a number between different numeric bases. Returns a string number for the number n, from the From_base base transformation to the to_base base, or null if any argument is null. Parameter n is interpreted as an integer, but can be specified as an integer or a string. The minimum base is 2 and the largest base is 36. If To_base is a negative number, n is considered to be a signed digit, otherwise n is treated as unsigned. Conv work with 64-bit precision.

mysql> Select conv ("a", 16,2);
-> ' 1010 '
Mysql> Select conv ("6e", 18,8);
-> ' 172 '
Mysql> Select conv ( -17,10,-18);
-> '-h '
Mysql> Select conv (10+ "ten" + ' +0xa,10,10 ');
-> '



Bin (N)
Returns a string representation of the binary value N, where n is a long integer (bigint) number, which is equivalent to Conv (n,10,2). If n is null, returns NULL.

mysql> Select Bin (12);
-> ' 1100 '

Oct (n)
Returns the representation of a string of octal value N, where n is a long integer number, which is equivalent to Conv (n,10,8). If n is null, returns NULL.

mysql> Select Oct (12);
-> '



Hex (N)
Returns the hexadecimal value n the representation of a string, where n is a long integer (bigint) number, which is equivalent to Conv (n,10,16). If n is null, returns NULL.

mysql> Select Hex (255);
-> ' FF '



CHAR (n,...)
char () interprets the argument as an integer and returns a string consisting of the ASCII code characters of these integers. The null value is skipped.

mysql> Select char (77,121,83,81, ' 76 ');
-> ' MySQL '
Mysql> Select char (77,77.3, ' 77.3 ');
-> ' mmm '


concat (str1,str2,...)


home 1 2 3 last

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.