![background image](http://html1.mh-extra.com/html/oracle/5-0/5-0_reference-manual_1646196907.webp)
String Functions
887
-> 'MMM'
As of MySQL 5.0.15,
CHAR()
[886]
arguments larger than 255 are converted into multiple
result bytes. For example,
CHAR(256)
[886]
is equivalent to
CHAR(1,0)
[886]
, and
CHAR(256*256)
[886]
is equivalent to
CHAR(1,0,0)
[886]
:
mysql>
SELECT HEX(CHAR(1,0)), HEX(CHAR(256));
+----------------+----------------+
| HEX(CHAR(1,0)) | HEX(CHAR(256)) |
+----------------+----------------+
| 0100 | 0100 |
+----------------+----------------+
mysql>
SELECT HEX(CHAR(1,0,0)), HEX(CHAR(256*256));
+------------------+--------------------+
| HEX(CHAR(1,0,0)) | HEX(CHAR(256*256)) |
+------------------+--------------------+
| 010000 | 010000 |
+------------------+--------------------+
By default,
CHAR()
[886]
returns a binary string. To produce a string in a given character set, use
the optional
USING
clause:
mysql>
SELECT CHARSET(CHAR(0x65)), CHARSET(CHAR(0x65 USING utf8));
+---------------------+--------------------------------+
| CHARSET(CHAR(0x65)) | CHARSET(CHAR(0x65 USING utf8)) |
+---------------------+--------------------------------+
| binary | utf8 |
+---------------------+--------------------------------+
If
USING
is given and the result string is illegal for the given character set, a warning is issued. Also,
if strict SQL mode is enabled, the result from
CHAR()
[886]
becomes
NULL
.
Before MySQL 5.0.15,
CHAR()
[886]
returns a string in the connection character set and
the
USING
clause is unavailable. In addition, each argument is interpreted modulo 256, so
CHAR(256)
[886]
and
CHAR(256*256)
[886]
both are equivalent to
CHAR(0)
[886]
.
•
CHAR_LENGTH(str)
[887]
Returns the length of the string
str
, measured in characters. A multi-byte character counts as a
single character. This means that for a string containing five 2-byte characters,
LENGTH()
[890]
returns
10
, whereas
CHAR_LENGTH()
[887]
returns
5
.
•
CHARACTER_LENGTH(str)
[887]
CHARACTER_LENGTH()
[887]
is a synonym for
CHAR_LENGTH()
[887]
.
•
CONCAT(str1,str2,...)
[887]
Returns the string that results from concatenating the arguments. May have one or more arguments.
If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any
binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary
string form; if you want to avoid that, you can use an explicit type cast, as in this example:
SELECT CONCAT(CAST(
int_col
AS CHAR),
char_col
);
CONCAT()
[887]
returns
NULL
if any argument is
NULL
.
mysql>
SELECT CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql>
SELECT CONCAT('My', NULL, 'QL');
-> NULL
mysql>
SELECT CONCAT(14.3);
-> '14.3'
For quoted strings, concatenation can be performed by placing the strings next to each other:
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...