SQL functions are built-in routines that perform operations on data and return a result. MySQL provides a rich library of functions covering string manipulation, numeric calculations, date handling, aggregation, and more.
Categories of MySQL Functions
- String functions: CONCAT, UPPER, LOWER, SUBSTRING, TRIM, LENGTH, REPLACE
- Numeric functions: ROUND, CEIL, FLOOR, ABS, MOD, POWER, SQRT
- Date functions: NOW, CURDATE, DATE_FORMAT, DATEDIFF, DATE_ADD, YEAR, MONTH
- Aggregate functions: COUNT, SUM, AVG, MIN, MAX
- Control flow: IF, IFNULL, COALESCE, CASE
Why Use Functions?
Functions let you transform and compute data directly in SQL without fetching raw values into application code. This reduces data transfer, simplifies queries, and keeps business logic close to the data.
Functions can appear in SELECT lists, WHERE clauses, ORDER BY clauses, and even in other function calls (nesting).