MySQL + SQL · Lesson 59
MySQL String Functions
Common String Functions
| Function | Does | Example → Result |
|---|---|---|
| CONCAT() | join text | CONCAT('Mr ',name) → Mr Aman |
| UPPER()/LOWER() | change case | UPPER('abc') → ABC |
| LENGTH() | length | LENGTH('cat') → 3 |
| SUBSTRING() | part of text | SUBSTRING('Hello',1,3) → Hel |
| TRIM() | remove spaces | TRIM(' hi ') → hi |
| REPLACE() | swap text | REPLACE('a-b','-','/') → a/b |
Example Query
SELECT CONCAT(name, ' (', class, ')') AS label,
UPPER(name) AS caps
FROM students;
Summary
- CONCAT joins, UPPER/LOWER change case, LENGTH counts.
- SUBSTRING extracts, TRIM cleans, REPLACE swaps text.