Relational databases process massive volumes of textual data: usernames, addresses, emails, and articles. Modern SQL dialects provide a comprehensive suite of built-in String Functions to format names, extract substrings, remove whitespace, and clean data before presentation.
| Function & Syntax | Description | Practical Example Output |
|---|---|---|
| CONCAT(s1, s2, ...) | Concatenates two or more strings together. | CONCAT('Aman', ' ', 'Verma') → 'Aman Verma' |
| CONCAT_WS(sep, s1, ...) | Concatenates with separator, automatically ignoring NULLs. | CONCAT_WS(', ', 'Delhi', 'India') → 'Delhi, India' |
| SUBSTRING(str, pos, len) | Extracts a substring starting at 1-based position for len characters. |
SUBSTRING('Veewom', 1, 4) → 'Veew' |
| UPPER(str) / LOWER(str) | Converts text to uppercase or lowercase. | UPPER('bca') → 'BCA' |
| TRIM(str) | Strips leading and trailing whitespace. | TRIM(' hello ') → 'hello' |
| REPLACE(str, from, to) | Replaces all occurrences of a substring. | REPLACE('2026/11/06', '/', '-') → '2026-11-06' |
| CHAR_LENGTH(str) | Returns character count of the text. | CHAR_LENGTH('Veewom') → 6 |
-- Format clean student full names and standardized uppercase emails
SELECT
student_id,
CONCAT(UPPER(last_name), ', ', first_name) AS formal_name,
LOWER(email) AS standardized_email,
SUBSTRING(enrollment_date, 1, 4) AS enrollment_year
FROM students;
Next, let us explore mathematical calculations using SQL Math & Numeric Functions!