SQL has a rich library of built-in scalar functions that transform values row by row — cleaning text, rounding numbers, and extracting date parts, right inside the query.
Common functions
-- StringsUPPER(name), LOWER(email), LENGTH(name)CONCAT(first, ' ', last) -- join stringsSUBSTRING(code, 1, 3), TRIM(name)-- NumbersROUND(package, 1), CEIL(x), FLOOR(x), ABS(x)-- DatesNOW(), CURRENT_DATEEXTRACT(YEAR FROM enrolled) -- or YEAR(enrolled) in MySQL-- NULL handlingCOALESCE(email, 'no email') -- first non-NULL value
Key takeaways
- 01Scalar functions transform values row by row inside a query.
- 02String (UPPER, CONCAT, TRIM), numeric (ROUND, ABS) and date (EXTRACT, NOW) functions cover most needs.
- 03COALESCE returns the first non-NULL value — great for defaults.
- 04Exact function names vary by database, but the categories are universal.
