CHAPTER 23
Manipulating and transforming text data.
| Function | What It Does | Example → Output |
|---|---|---|
| UPPER(str) | Convert to uppercase | UPPER('sql book') → 'SQL BOOK' |
| LOWER(str) | Convert to lowercase | LOWER('SQL') → 'sql' |
| TRIM(str) | Remove leading + trailing spaces | TRIM(' hi ') → 'hi' |
| LENGTH(str) | Number of characters | LENGTH('Arjun') → 5 |
| CONCAT(s1,s2,...) | Join strings | CONCAT('Hello','SQL') → 'Hello SQL' |
| LEFT(str,n) | First n characters | LEFT('Bangalore',4) → 'Bang' |
| RIGHT(str,n) | Last n characters | RIGHT('Bangalore',4) → 'lore' |
| SUBSTRING(s,pos,n) | Extract n chars from position | SUBSTRING('Hyderabad',2,5) → 'yderi' |
| REPLACE(s,old,new) | Replace all occurrences | REPLACE('SQL is hard','hard','easy') |
| INSTR(str,sub) | Position of substring | INSTR('Hyderabad','bad') → 7 |
Full display string with city
SELECT CONCAT(name, ' — ', city, ', ', country) AS profile FROM customers;
| emp_id | name | department | salary | manager_id | hire_date |
|---|---|---|---|---|---|
| 1 | Arjun | IT | 85000 | NULL | 2020-06-15 |
| 2 | Priya | IT | 72000 | 1 | 2021-03-10 |
| 3 | Rahul | Sales | 55000 | 5 | 2022-01-20 |
| 4 | Sneha | HR | 60000 | 5 | 2021-07-08 |
| 5 | Vikram | Sales | 90000 | NULL | 2019-11-01 |
| 6 | Divya | IT | 68000 | 1 | 2023-02-14 |
| 7 | Kiran | HR | 58000 | 4 | 2022-08-30 |
| 8 | Meera | Sales | 62000 | 5 | 2023-05-12 |
| customer_id | name | city | country |
|---|---|---|---|
| 1 | Ananya | Hyderabad | India |
| 2 | Rohan | Bangalore | India |
| 3 | Sam | Mumbai | India |
| 4 | Lisa | London | UK |
| 5 | Ravi | Delhi | India |