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