A detailed explanation of string functions in MySQL

Source: Internet
Author: User

A string or series (string) is a finite sequence of 0 or more characters. Generally recorded as s= ' a1a2 an ' (n>=0). It is the data type that represents text in the programming language.

A string is usually used as an action object, such as finding a substring in a string, seeking a substring, inserting a substring at a point in a string, and deleting a substring. The necessary and sufficient condition for two strings to be equal is that the length is equal and the characters on each corresponding position are equal. To set P and Q to be two strings, the operation of Q for the first place in P is called pattern matching. The two most basic types of storage for a string are sequential storage and linked storage.

Let's look at the string functions in MySQL

If the length of the result is greater than the maximum value of the Max_allowed_packet system variable, the return value of the string value function is null.

For functions that operate at the string position, the first position is numbered 1.

ASCII (str)

Returns the value of the leftmost character of String Str. If Str is an empty string, the return value is 0. If STR is NULL, the return value is null. ASCII () is used for characters with numeric values ranging from 0 to 255.

mysql> SELECT ASCII('2');

    -> 50

mysql> SELECT ASCII(2);

    -> 50

mysql> SELECT ASCII('dx');

    -> 100

See ORD () function.

BIN (N)

Returns a string representation of the binary value of n, where N is a longlong (BIGINT) number. This equates to CONV (n,10,2). If n is null, the return value is null.

mysql> SELECT BIN(12);
-> '1100'

Bit_length (str)

Returns the string str length of the binary value.

mysql> SELECT BIT_LENGTH('text');
-> 32

CHAR (N,... [USING CharSet])

CHAR () understands each parameter n as an integer that returns a string containing the character given by the code value of these integers. Null value is omitted.

mysql> SELECT CHAR(77,121,83,81,'76');
-> 'MySQL'
mysql> SELECT CHAR(77,77.3,'77.3');
-> 'MMM'

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.