You are on page 1of 1

MySQL 

CHEAT SHEET: STRING FUNCTIONS by sqlbackupandftp.com  with  ♥

MEASUREMENT CONVERSION MODIFICATION


Return a string containing binary representation of a Return numeric value of left­most character Return concatenated string Remove trailing spaces
number
ASCII ('2') = 50 CONCAT ('My', 'S', 'QL') = 'MySQL' RTRIM ('MySql      ') = 'MySql'
BIN (12) = '1100' ASCII (2) = 50 CONCAT ('My', NULL, 'QL') = NULL
ASCII ('dx') = 100 CONCAT (14.3) = '14.3' Return a string of the specified number of spaces
Return length of argument in bits
SPACE ('6') = '      '
Return the character for each number passed Return concatenate with separator
BIT_LENGTH ('MySql') = 40
CHAR (77.3,121,83,81, '76, 81.6') = 'MySQL' CONCAT_WS (',', 'My', 'Sql') = 'My,Sql' Return the substring as specified
Return number of characters in argument
CHAR (45*256+45) = CHAR (45,45) = '‐‐' CONCAT_WS (',','My',NULL,'Sql') = 'My,Sql' SUBSTRING=SUBSTR=MID('MySql',3) = 'Sql'
CHAR_LENGTH ('MySql') = 5 CHARSET(CHAR (X'65' USING utf8)) = 'utf8' SUBSTRING=SUBSTR=MID('MySql' FROM 4) = 'ql'
Return a number formatted to specified number of decimal
CHARACTER_LENGTH ('MySql') = 5 SUBSTRING=SUBSTR=MID('MySql',3,1) = 'S'
Decode to / from a base­64 string places
SUBSTRING=SUBSTR=MID('MySql',‐3) = 'Sql'
Return the length of a string in bytes FORMAT (12332.123456, 4) = 12,332.1235
TO_BASE64 ('abc') = 'YWJj' SUBSTRING=SUBSTR=MID('MySql' FROM ‐4 FOR 2)
LENGTH ('Ö') = 2 FROM_BASE64 ('YWJj') = 'abc' FORMAT (12332.1, 4) = 12,332.1000 = 'yS'
LENGTH ('A') = 1 FORMAT (12332.2, 0) = 12332.2
Convert string or number to its hexadecimal representation FORMAT (12332.2, 2, 'de_DE') = 12.332,20 Remove leading and trailing spaces
OCTET_LENGTH ('Ö') = 2
OCTET_LENGTH ('X') = 1 X'616263' = 'abc' TRIM(' MySql ') = 'MySql'
Insert a substring at the specified position up to the
HEX ('abc') = 616263 specified number of characters TRIM(LEADING 'x' FROM 'xxxSqlMy') = 'MySql'
Return a soundex string
HEX(255) = 'FF' TRIM(BOTH 'My' FROM 'MySqlMy') = 'Sql'
SOUNDEX ('MySql') = 'M240' CONV(HEX(255), 16, 10) = 255 INSERT ('12345', 3, 2, 'ABC') = '12ABC5' TRIM(TRAILING 'Sql' FROM 'MySql') = 'My'
SOUNDEX ('MySqlDatabase') = 'M24312' INSERT ('12345', 10, 2, 'ABC') = '12345'
Convert each pair of hexadecimal digits to a character INSERT ('12345', 3, 10, 'ABC') = '12ABC'
Compare two strings
STRCMP ('A', 'A') = 0
UNHEX ('4D7953514C') = 'MySQL'
UNHEX ('GG') = NULL
Return the leftmost number of characters as specified SETS
STRCMP ('A', 'B') = ‐1 UNHEX (HEX ('abc')) = 'abc' LEFT ('MySql', 2) = 'My' Return string at index number
STRCMP ('B', 'A') = 1 Return the string argument, left­padded with the specified ELT (1, 'ej', 'Heja', 'hej', 'foo') = 'ej'
Return the argument in lowercase
string ELT (4, 'ej', 'Heja', 'hej', 'foo') = 'foo'
LOWER ('MYSQL') = 'mysql'
LPAD ('Sql', 2, ':)') = 'Sq'
SEARCH LCASE ('MYSQL') = 'mysql'
LPAD ('Sql', 4, ':)') = ':Sql'
Return a string such that for every bit set in the value bits,
you get an on string and for every unset bit, you get an off
Load the named file LPAD ('Sql', 7, ':)') = ':):)Sql' string
Return the index of the first occurrence of substring
INSTR ('MySql', 'Sql') = 3 SET blob_col=LOAD_FILE ('/tmp/picture') Remove leading spaces EXPORT_SET (5,'Y','N',',',4) = 'Y,N,Y,N'
INSTR ('Sql', 'MySql') = 0 EXPORT_SET (6,'1','0',',',6) = '0,1,1,0,0,0'
Return a string containing octal representation of a number LTRIM ('      MySql') = 'MySql'
Return the position of the first occurrence of substring Return the index (position) of the first argument in the
OCT (12) = '14' Repeat a string the specified number of times subsequent arguments
LOCATE ('Sql', 'MySqlSql') = 3 Return character code for leftmost character of the REPEAT ('MySQL', 3) = 'MySQLMySQLMySQL'
LOCATE ('xSql', 'MySql') = 0 FIELD ('ej','Hj','ej','Heja','hej','oo') = 2
argument
LOCATE ('Sql', 'MySqlSql', 5) = 6 Replace occurrences of a specified string FIELD ('fo','Hj','ej','Heja','hej','oo') = 0
POSITION('Sql' IN 'MySqlSql') = 3 ORD ('2') = 50
REPLACE ('NoSql', 'No', 'My') = 'MySql' Return the index position of the first argument within the
Escape the argument for use in an SQL statement second argument
Pattern matching using regular expressions
Reverse the characters in a string
QUOTE ('Don\'t!') = 'Don\'t!' FIND_IN_SET ('b', 'a,b,c,d') = 2
'abc' RLIKE '[a‐z]+' = 1
QUOTE (NULL) = 'NULL' REVERSE ('MySql') = 'lqSyM' FIND_IN_SET ('z', 'a,b,c,d') = 0
'123' RLIKE '[a‐z]+' = 0
FIND_IN_SET ('a,', 'a,b,c,d') = 0
Convert to uppercase Return the specified rightmost number of characters
Return a substring from a string before the specified
number of occurrences of the delimiter Return a set of comma­separated strings that have the
UPPER ('mysql') = 'MYSQL' RIGHT ('MySql', 3) = 'Sql' corresponding bit in bits set
SUBSTRING_INDEX ('A:B:C', ':', 1) = 'A' UCASE ('mysql') = 'MYSQL'
Returns the string argument, right­padded with the MAKE_SET (1,'a','b','c') = 'a'
SUBSTRING_INDEX ('A:B:C', ':', 2) = 'A:B' specified strin. MAKE_SET (1|4,'ab','cd','ef') = 'ab,ef'
SUBSTRING_INDEX ('A:B:C', ':', ‐2) = 'B:C'
RPAD ('Sql', 2, ':)') = 'Sq' MAKE_SET (1|4,'ab','cd',NULL,'ef') = 'ab'
RPAD ('Sql', 4, ':)') = 'Sql:' MAKE_SET (0,'a','b','c') = ''
RPAD ('Sql', 7, ':)') = 'Sql:):)'

You might also like