String Functions in SQL

From the SQL cheat sheet ยท Built-in Functions ยท verified Jul 2026

String Functions

Manipulate and transform text data.

sql
SELECT UPPER('hello');               -- HELLO
SELECT LOWER('HELLO');               -- hello
SELECT LENGTH('hello');              -- 5
SELECT TRIM('  hello  ');            -- hello
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users;
SELECT SUBSTRING(name, 1, 3) FROM users;  -- First 3 chars
SELECT REPLACE(email, '@old.com', '@new.com') FROM users;
๐Ÿ’ก CONCAT works across databases; || is PostgreSQL/SQLite only, + is SQL Server only
โšก SUBSTRING(col, start, length) โ€” start position is 1-based, not 0-based
๐Ÿ“Œ Function names vary: LENGTH (MySQL/PG) vs LEN (SQL Server), CHARINDEX vs POSITION
๐ŸŸข LPAD with zeros is a common trick for formatting IDs: LPAD(id, 5, '0') โ†’ 00042
stringsfunctionsconcatsubstring

More SQL tasks

Back to the full SQL cheat sheet