String Functions
894
•
SUBSTR(str,pos)
[894]
,
SUBSTR(str FROM pos)
[894]
,
SUBSTR(str,pos,len)
[894]
,
SUBSTR(str FROM pos FOR len)
[894]
SUBSTR()
[894]
is a synonym for
SUBSTRING()
[894]
.
•
SUBSTRING(str,pos)
[894]
,
SUBSTRING(str FROM pos)
[894]
,
SUBSTRING(str,pos,len)
[894]
,
SUBSTRING(str FROM pos FOR len)
[894]
The forms without a
len
argument return a substring from string
str
starting at position
pos
.
The forms with a
len
argument return a substring
len
characters long from string
str
, starting at
position
pos
. The forms that use
FROM
are standard SQL syntax. It is also possible to use a negative
value for
pos
. In this case, the beginning of the substring is
pos
characters from the end of the
string, rather than the beginning. A negative value may be used for
pos
in any of the forms of this
function.
For all forms of
SUBSTRING()
[894]
, the position of the first character in the string from which the
substring is to be extracted is reckoned as
1
.
mysql>
SELECT SUBSTRING('Quadratically',5);
-> 'ratically'
mysql>
SELECT SUBSTRING('foobarbar' FROM 4);
-> 'barbar'
mysql>
SELECT SUBSTRING('Quadratically',5,6);
-> 'ratica'
mysql>
SELECT SUBSTRING('Sakila', -3);
-> 'ila'
mysql>
SELECT SUBSTRING('Sakila', -5, 3);
-> 'aki'
mysql>
SELECT SUBSTRING('Sakila' FROM -4 FOR 2);
-> 'ki'
This function is multi-byte safe.
If
len
is less than 1, the result is the empty string.
•
SUBSTRING_INDEX(str,delim,count)
[894]
Returns the substring from string
str
before
count
occurrences of the delimiter
delim
. If
count
is positive, everything to the left of the final delimiter (counting from the left) is returned. If
count
is negative, everything to the right of the final delimiter (counting from the right) is returned.
SUBSTRING_INDEX()
[894]
performs a case-sensitive match when searching for
delim
.
mysql>
SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
-> 'www.mysql'
mysql>
SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
-> 'mysql.com'
This function is multi-byte safe.
•
TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
[894]
,
TRIM([remstr
FROM] str)
[894]
Returns the string
str
with all
remstr
prefixes or suffixes removed. If none of the specifiers
BOTH
,
LEADING
, or
TRAILING
is given,
BOTH
is assumed.
remstr
is optional and, if not specified, spaces
are removed.
mysql>
SELECT TRIM(' bar ');
-> 'bar'
mysql>
SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx');
-> 'barxxx'
mysql>
SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');
-> 'bar'
mysql>
SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');
-> 'barx'
Содержание 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 ...