SQL Data Analytics • Lesson 12
String Functions
Learn how SQL cleans, transforms, measures and analyzes text stored inside database columns.
0 of 8 concepts completed
Complete the activity and related MCQ to unlock the next concept.
Why Analysts Need String Functions
Names arrive with extra spaces, cities use mixed capitalization, emails are inconsistent. String functions clean, transform and analyze that text before it reaches a report.
Interactive Data
Raw vs Clean
The same four customer rows before and after applying TRIM, UPPER and LOWER. Quotes mark the exact stored value — extra spaces are visible inside the quotes.
Before
| name | city | |
|---|---|---|
| " Rahul Sharma " | "dehradun" | "RAHUL@EMAIL.COM" |
| "Priya Singh" | "MUMBAI" | "priya@email.com" |
| " Amit Kumar" | "Delhi" | "AMIT@EMAIL.COM" |
| "Neha Verma " | "Pune" | "neha@email.com" |
After TRIM / UPPER / LOWER
| clean_name | clean_city | clean_email |
|---|---|---|
| Rahul Sharma | DEHRADUN | rahul@email.com |
| Priya Singh | MUMBAI | priya@email.com |
| Amit Kumar | DELHI | amit@email.com |
| Neha Verma | PUNE | neha@email.com |
Learn by Seeing
Three jobs for string functions
CLEAN → remove spaces, fix case TRANSFORM → rename, replace, combine ANALYZE → measure, extract parts
Almost every string transformation falls into one of these three categories.
Click a category to explore what string functions do:
CLEAN
Remove invisible spaces and fix inconsistent capitalization so equal values actually match.
" delhi " → TRIM + UPPER → "DELHI"
Interactive Activity
Which of these best describes why string functions matter?
Hint: Think about 'delhi' vs 'DELHI' in a grouping query.
SQL Analyst Mindset
Text is data too
Most datasets are more than half text. Cleaning and standardizing text with string functions is what makes joins, groupings and filters actually work as intended.
Inspect
Look for spaces, mixed case, separators.
Standardize
TRIM, UPPER, LOWER.
Reshape
CONCAT, REPLACE, LEFT, RIGHT.
Validate
Does the cleaned text group correctly?
Frequently Asked Questions
SQL String Functions — FAQs
No. TRIM only removes leading and trailing spaces — spaces between words are preserved.
Yes. LENGTH counts every character, including spaces and punctuation.
Similar idea, but CONCAT is the standard, portable function across most SQL databases and handles NULLs more gracefully.
No. REPLACE only changes the value in the query result — the underlying stored data stays untouched unless you run an UPDATE.
Lesson Summary
What you learned
Standardize capitalization.
Remove leading and trailing spaces.
Measure the number of characters.
Extract, combine and substitute text values.