String Functions
Common text functions are UPPER, LOWER, LENGTH, TRIM, SUBSTR (SUBSTRING in other databases) and REPLACE. Join text with || (or CONCAT in MySQL and SQL Server).
Example
SELECT UPPER(name) AS shout, LENGTH(name) AS letters
FROM students
WHERE id <= 3;Result
shout | letters ADA | 3 KOFI | 4 AMINA | 5
Example
SELECT name || ' from ' || country AS summary
FROM students
WHERE id = 1;Result
summary Ada from Nigeria
Example
SELECT REPLACE(title, 'Basics', 'Intro') AS renamed, SUBSTR(title, 1, 3) AS short
FROM courses
WHERE id = 2;Result
renamed | short CSS Intro | CSS
- SQL Server joins text with + or CONCAT, and MySQL uses CONCAT. SUBSTR is called SUBSTRING in MySQL, PostgreSQL and SQL Server.
Exercise
Make the text uppercase.
SELECT (name) FROM students;
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.