Note: If the function parameter is not surrounded by
quotation marks
, then the parameter is going to be interpreted as a column value.
Converts a string or column value to
UPPER-CASE
SELECT
UPPER(first_name),
UPPER('Converts a string or column value to UPPER-CASE')
FROM students
Converts a string or column value to
lower-case
SELECT
LOWER(first_name),
LOWER('Converts a string or column value to lower-case')
FROM students
Joins strings and columns together
SELECT
CONCAT(first_name, ' ', 'joins', ' ', 'strings', ' ', 'and', ' ', 'columns')
FROM students
The function
LENGTH
Returns the length (in bytes)
SELECT
id,
first_name,
LENGTH(first_name) first_name_length
FROM students
Note: Each Georgian letter takes
three bytes
The function is similar to
CONCAT
where
WS
means - With Separator.
The first parameter is the separator between each one of the additional fields, that we pass as next parameters
SELECT
CONCAT_WS(' - ', first_name, 'joins', 'strings', 'and', 'columns', 'with', 'separator')
FROM students
The function
TRIM
removes leading and trailing spaces
SELECT
LENGTH(' text ') length,
LENGTH(TRIM(' text ')) length_with_trim
The function
RTRIM
removes trailing spaces (removes spaces from the end)
SELECT
LENGTH(' text ') length,
LENGTH(RTRIM(' text ')) length_with_right_trim
The function
LTRIM
remove leading spaces (removes spaces from the beginning)
SELECT
LENGTH(' text ') length,
LENGTH(LTRIM(' text ')) length_with_left_trim
The function
LEFT
returns leftmost characters. In this case 5 characters because we pass 5 as second parameter
SELECT
LEFT(first_name, 5) AS 'five leftmost characters'
FROM students
The function
RPAD
appends string (third parameter) the specified number of times (second parameter) to the first parameter.
In this example each one of the student's last name that is less than 10 characters long, is filled with
-
SELECT
RPAD(first_name, 10, '-') AS 'student name'
FROM students
Complete list of string functions on the official documentation: https://dev.mysql.com/doc/refman/8.0/en/string-functions.html