SQL String Functions

Source: Internet
Author: User

Http://www.w3cschool.cn/sql/sql-string-functions.html

SQL String Functions

Serial number

Name

Description

Note

1

ASCII ()

Returns the value of the leftmost character

ASCII code of the source content can be used in a pair of char () data parsing import operations;

2

CHAR ()

Returns the character of each passed integer

3

HEX ()

Returns the string representation of a hexadecimal value

Unhex () can be used for data import operation with Hex pairing;

4

Unhex ()

Converts each pair of hexadecimal digits to one character

ASCII (STR)

Returns the value of the leftmost character of the string str. If Str is an empty string, return 0. , then null STR is returned as NULL. The ASCII () character that applies to numeric values from 0 to 255.

sql> SELECT ASCII (' 2 ');

+---------------------------------------------------------+

| ASCII (' 2 ') |

+---------------------------------------------------------+

| 50 |

+---------------------------------------------------------+

1 row in Set (0.00 sec)

sql> SELECT ASCII (' DX ');

+---------------------------------------------------------+

| ASCII (' DX ') |

+---------------------------------------------------------+

| 100 |

+---------------------------------------------------------+

1 row in Set (0.00 sec)

CHAR () interprets each parameter n as an integer and returns a string of characters given by the code value of those integers. A null value was skipped.

Sql> SELECT CHAR (77,121,83,81, ' 76 ');
+---------------------------------------------------------+
| CHAR (77,121,83,81, ' 76 ') |
+---------------------------------------------------------+
| MySQL |
+---------------------------------------------------------+
1 row in Set (0.00 sec)

HEX (n_or_s)

If n_or_s is a number, returns N, where n is a string representation of the hexadecimal value of a longlong (BIGINT) number. This is equivalent to conv (n,10,16).

If n_or_s is a string, returns a hexadecimal string representation of n_or_s where n_or_s each character is converted to two hexadecimal digits.

sql> SELECT HEX (255);
+---------------------------------------------------------+
| HEX (255) |
+---------------------------------------------------------+
| FF |
+---------------------------------------------------------+
1 row in Set (0.00 sec)
Sql> SELECT 0x616263;
+---------------------------------------------------------+
| 0x616263 |
+---------------------------------------------------------+
| ABC |
+---------------------------------------------------------+
1 row in Set (0.00 sec)

Unhex (STR)

Executes the inverse of Hex (STR). That is, it interprets the arguments for each pair of hexadecimal digits as numbers and converts them to characters represented by numbers. The resulting character is returned as a binary string.

sql> SELECT unhex (' 4d7953514c ');
+---------------------------------------------------------+
| Unhex (' 4d7953514c ') |
+---------------------------------------------------------+
| SQL |
+---------------------------------------------------------+
1 row in Set (0.00 sec)

The character in the argument string must be a valid hexadecimal number: ' 0 ' ... ' 9 ', ' A ' ... ' F ', ' one ' ... F '. If Unhex () encounters any non-hexadecimal number in the parameter, it returns NULL.

SQL String Functions

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.