SQL String Functions

String functions clean and reshape text: change case, cut out pieces, join values together. Names vary a little between databases; the examples here use SQLite, with notes for others.

Updated December 1, 2026

Syntax

UPPER(text)   LOWER(text)   LENGTH(text)
SUBSTR(text, start, length)   REPLACE(text, old, new)
text1 || text2

Change case and measure length

UPPER, LOWER and LENGTH work the same way in almost every database.

SELECT name, UPPER(name) AS shout, LENGTH(name) AS letters
FROM customers;
Result on the Desk & Co. (online store) sample data (8 rows, first 4 shown)
nameshoutletters
Amara ObiAMARA OBI9
Bruno CostaBRUNO COSTA11
Chen WeiCHEN WEI8
Dana LeviDANA LEVI9

Join text together

|| concatenates. MySQL and SQL Server use CONCAT(a, b) instead.

SELECT name || ' (' || country || ')' AS label
FROM customers;
Result on the Desk & Co. (online store) sample data (8 rows, first 4 shown)
label
Amara Obi (Nigeria)
Bruno Costa (Brazil)
Chen Wei (China)
Dana Levi (Israel)

Cut and replace

SUBSTR(text, start) counts from 1 and, without a length, runs to the end. INSTR finds where a piece of text starts, so together they can take everything after the first space.

SELECT name,
       SUBSTR(name, INSTR(name, ' ') + 1) AS last_name,
       REPLACE(LOWER(title), ' ', '-') AS title_slug
FROM employees;
Result on the Acme Co. (company data) sample data (15 rows, first 5 shown)
namelast_nametitle_slug
Maya ChenChenvp-engineering
Omar HaddadHaddadstaff-engineer
Lena ParkParksenior-engineer
Ravi PatelPatelengineer
Sofia RossiRossiengineer

Common mistakes

Practice String Functions interactively

Write real queries in your browser and get instant feedback in the lesson “Text functions” (Unit 7). New learners can start free from the first lesson.

Frequently asked questions

How do I concatenate strings in SQL?

Use || in SQLite, PostgreSQL and Oracle; use CONCAT() in MySQL and SQL Server (which also supports +).

What is the difference between LENGTH and LEN?

Same idea, different names: LEN in SQL Server, LENGTH elsewhere.

Related SQL tutorials