ASCII(S)
S. If
S is NULL return NULL.
mysql> SELECT ascii(2); -> 50
mysql> SELECT ascii('dx'); -> 100
CHAR(X,...)
NULLs are skipped.
mysql> SELECT char(77,121,83,81,'76'); -> 'MySQL'
CONCAT(X,Y...)
mysql> SELECT CONCAT('My', 'S', 'QL'); -> 'MySQL'
LENGTH(S)
OCTET_LENGTH(S)
CHAR_LENGTH(S)
CHARACTER_LENGTH(S)
mysql> SELECT length('text'); -> 4
mysql> SELECT octet_length('text'); -> 4
LOCATE(A,B)
POSITION(B IN A)
A substring in B. The first position
is 1. Returns 0 if A is not in B.
mysql> select locate('bar', 'foobarbar'); -> 4
mysql> select locate('xbar', 'foobar'); -> 0
INSTR(A,B)
B in string A. This is
the same as LOCATE with swapped parameters.
mysql> select instr('foobarbar', 'bar'); -> 4
mysql> select instr('xbar', 'foobar'); -> 0
LOCATE(A,B,C)
A in string B starting
at C.
mysql> select locate('bar', 'foobarbar',5); -> 7
LEFT(str,length)
mysql> select left('foobarbar', 5); -> 'fooba'
RIGHT(A,B)
SUBSTRING(A FROM B)
B characters from end of string A.
mysql> select right('foobarbar', 5); -> 'arbar'
mysql> select substring('foobarbar' from 5); -> 'arbar'
LTRIM(str)
mysql> select ltrim(' barbar'); -> 'barbar'
RTRIM(str)
TRIM([[ BOTH | LEADING | TRAILING] [ A ] FROM ] B)
A prefixes and/or suffixes
removed from B. If BOTH, LEADING and
TRAILING isn't used BOTH are assumed. If A is not
given, then 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'
SOUNDEX(S)
S. Two strings that sound 'about the
same' should have identical soundex strings. A 'standard' soundex string
is 4 characters long, but this function returns an arbitrary long
string. One can use SUBSTRING on the result to get a 'standard'
soundex string. All non alpha characters are ignored in the given
string. All characters outside the A-Z range are treated as vocals.
mysql> select soundex('Hello'); -> 'H400'
mysql> select soundex('Bättre'); -> 'B360'
mysql> select soundex('Quadratically'); -> 'Q36324'
SUBSTRING(A, B, C)
SUBSTRING(A FROM B FOR C)
MID(A, B, C)
A starting at B with C
chars. The variant with FROM is ANSI SQL 92 syntax.
mysql> select substring('Quadratically',5,6); -> ratica
SUBSTRING_INDEX(String, Delimiter, Count)
String after Count
Delimiters. If Count is positive the strings are searched
from left else if count is negative the substrings are searched and
returned from right.
mysql> select substring_index('www.tcx.se', '.', 2); -> 'www.tcx'
mysql> select substring_index('www.tcx.se', '.', -2); -> 'tcx.se'
SPACE(N)
N spaces.
mysql> select SPACE(6); -> ' '
REPLACE(A, B, C)
B in string A with
string C.
mysql> select replace('www.tcx.se', 'w', 'Ww'); -> 'WwWwWw.tcx.se'
REPEAT(String, Count)
String Count times. If Count <= 0 returns a
empty string. If String or Count is NULL or
LENGTH(string)*count > max_allowed_size returns NULL.
mysql> select repeat('MySQL', 3); -> 'MySQLMySQLMySQL'
REVERSE(String)
mysql> select reverse('abc'); -> 'cba'
INSERT(Org, Start, Length, New)
Org starging at Start and
Length long with New. First position in Org is
numbered 1.
mysql> select insert('Quadratic', 3, 4, 'What'); -> 'QuWhattic'
INTERVAL(N, N1, N2, N3...)
Nn > N3 > N2 > N1 is
this function shall work. This is because a binary search is used (Very
fast). Returns 0 if N < N1, 1 if N < N2 and
so on. All arguments are treated as numbers.
mysql> select INTERVAL(23, 1, 15, 17, 30, 44, 200); -> 3 mysql> select INTERVAL(10, 1, 10, 100, 1000); -> 2 mysql> select INTERVAL(22, 23, 30, 44, 200); -> 0
ELT(N, A1, A2, A3...)
A1 if N = 1, A2 if N = 2 and so
on. If N is less than 1 or bigger than the number of arguments
NULL is returned.
mysql> select elt(1, 'ej', 'Heja', 'hej', 'foo'); -> 'ej' mysql> select elt(4, 'ej', 'Heja', 'hej', 'foo'); -> 'foo'
FIELD(S, S1, S2, S3...)
S in S1, S2,
S3... list. The complement of ELT(). Return 0 when S is
not found.
mysql> select FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo'); -> 2
mysql> select FIELD('fo', 'Hej', 'ej', 'Heja', 'hej', 'foo'); -> 0
FIND_IN_SET(string,string of strings)
mysql> SELECT FIND_IN_SET('b','a,b,c,d') -> 2
This function will not work properly if the first argument contains a ','.
LCASE(A)
LOWER(A)
A to lower case according to current character set
,dmappings (Default Latin1).
mysql> select lcase('QUADRATICALLY'); -> 'quadratically'
UCASE(A)
UPPER(A)
A to upper case.
mysql> select ucase('Hej'); -> 'HEJ'
Go to the first, previous, next, last section, table of contents.