Tutorial by Examples

SELECT FIND_IN_SET('b','a,b,c'); Return value: 2 SELECT FIND_IN_SET('d','a,b,c'); Return value: 0
With a column of one of the string types, named my_date_field with a value such as [the string] 07/25/2016, the following statement demonstrates the use of the STR_TO_DATE function: SELECT STR_TO_DATE(my_date_field, '%m/%d/%Y') FROM my_table; You could use this function as part of WHERE clause a...
Convert in lowercase the string argument Syntax: LOWER(str) LOWER('fOoBar') -- 'foobar' LCASE('fOoBar') -- 'foobar'
Convert in lowercase the string argument Syntax: REPLACE(str, from_str, to_str) REPLACE('foobarbaz', 'bar', 'BAR') -- 'fooBARbaz' REPLACE('foobarbaz', 'zzz', 'ZZZ') -- 'foobarbaz'
SUBSTRING (or equivalent: SUBSTR) returns the substring starting from the specified position and, optionally, with the specified length Syntax: SUBSTRING(str, start_position) SELECT SUBSTRING('foobarbaz', 4); -- 'barbaz' SELECT SUBSTRING('foobarbaz' FROM 4); -- 'barbaz' -- using negative index...
Convert in uppercase the string argument Syntax: UPPER(str) UPPER('fOoBar') -- 'FOOBAR' UCASE('fOoBar') -- 'FOOBAR'
Return the length of the string in bytes. Since some characters may be encoded using more than one byte, if you want the length in characters see CHAR_LENGTH() Syntax: LENGTH(str) LENGTH('foobar') -- 6 LENGTH('fööbar') -- 8 -- contrast with CHAR_LENGTH(...) = 6
Return the number of characters in the string Syntax: CHAR_LENGTH(str) CHAR_LENGTH('foobar') -- 6 CHAR_LENGTH('fööbar') -- 6 -- contrast with LENGTH(...) = 8
Convert the argument to hexadecimal. This is used for strings. HEX('fööbar') -- 66F6F6626172 -- in "CHARACTER SET latin1" because "F6" is hex for ö HEX('fööbar') -- 66C3B6C3B6626172 -- in "CHARACTER SET utf8 or utf8mb4" because "C3B6" is hex for ö

Page 1 of 1