웹이야기

[MySQL] CHAR() 본문

D/MySQL

[MySQL] CHAR()

yeon.Biju 2020. 4. 8. 12:52

MySQL 문자열 함수와 연산자

 

CHAR()

   -

 

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

의 형태

 

CHAR() interprets each argument N as an integer and returns a string consisting of the characters given by the code values of those integers. NULL value are skipped.

 

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

 


mysql> SELECT HEX(CHAR(1, 0)), HEX(CHAR(256));
+-----------------+----------------+
| HEX(CHAR(1, 0)) | HEX(CHAR(256)) |
+-----------------+----------------+
| 0100            | 0100           |
+-----------------+----------------+
1 row in set (0.00 sec)

 

mysql> SELECT HEX(CHAR(1, 0, 0)), HEX(CHAR(256*256));
+--------------------+--------------------+
| HEX(CHAR(1, 0, 0)) | HEX(CHAR(256*256)) |
+--------------------+--------------------+
| 010000             | 010000             |
+--------------------+--------------------+
1 row in set (0.00 sec)

 

By deault, CHAR() returns a binary string. To produce a string given character set, use the optional USING clause:

 

mysql> SELECT CHARSET(CHAR(X'65')), CHARSET(CHAR(X'65' USING utf8));
+----------------------+---------------------------------+
| CHARSET(CHAR(X'65')) | CHARSET(CHAR(X'65' USING utf8)) |
+----------------------+---------------------------------+
| binary               | utf8                            |
+----------------------+---------------------------------+
1 row in set, 1 warning (0.00 sec)

 

 

'D > MySQL' 카테고리의 다른 글

[MySQL] CHARACTER_LENGTH()  (0) 2020.04.08
[MySQL] CHAR_LENGTH()  (0) 2020.04.08
[MySQL] BIT_LENGTH()  (0) 2020.04.08
[MySQL] BIN()  (0) 2020.04.08
[MySQL] ASCII()  (0) 2020.04.08
Comments