A function takes values and returns a value. You used version() in Chapter 1. Most functions take values in the parentheses: UPPER(name).
You can use a function anywhere you can use a column: in the SELECT list, in WHERE and in ORDER BY.
Text
| Function | Returns | Example | Result |
|---|---|---|---|
UPPER(t) | the text in upper case | UPPER('Ava') | AVA |
LOWER(t) | the text in lower case | LOWER('Ava') | ava |
LENGTH(t) | the number of characters | LENGTH('Ava Chen') | 8 |
Numbers
ROUND(x, n) rounds x to n decimal places. ROUND(33.8887, 2) is 33.89. Without n, it rounds to a whole number.
NULL
COALESCE(a, b, …) returns the first value that is not NULL. Use it to show a value in place of NULL:
sql
SELECT name, COALESCE(city, 'unknown') AS city
FROM customers;result
| name | city |
|---|---|
| Diego Lopez | Monterrey |
| Grace Okafor | unknown |
Dates
| Expression | Returns | Example result |
|---|---|---|
CURRENT_DATE | today's date (no parentheses) | 2026-10-14 |
EXTRACT(YEAR FROM d) | one part of a date as a number: YEAR, MONTH, DAY | 2025 |
d + 7 | the date 7 days later | 2025-03-15 |
d1 - d2 | the number of days between two dates | 31 |