SQL provides various numeric functions that help perform mathematical operations on numeric data. These functions are useful for calculations, rounding, and other numerical transformations.

Common Numeric Functions

Example Usage of Numeric Functions

1. Using ABS() Function

SELECT ABS(-15) AS AbsoluteValue;

Output. 15

2. Using CEILING() and FLOOR() Functions

SELECT CEILING(4.3) AS CeilValue, FLOOR(4.7) AS FloorValue;

Output

CeilValue FloorValue
5 4

3. Using ROUND() and TRUNCATE() Functions

SELECT ROUND(123.456, 2) AS RoundedValue, TRUNCATE(123.456, 2) AS TruncatedValue;

Output

RoundedValue TruncatedValue
123.46 123.45

4. Using POWER() and SQRT() Functions

SELECT POWER(5, 3) AS PowerValue, SQRT(25) AS SquareRoot;

Output

PowerValue SquareRoot
125 5

5. Using MOD() Function

SELECT MOD(10, 3) AS ModResult;

Output. 1

6. Using PI(), DEGREES(), and RADIANS() Functions

SELECT 
    PI() AS PiValue, 
    DEGREES(PI()) AS DegreesValue, 
    RADIANS(180) AS RadiansValue;

Output

PiValue DegreesValue RadiansValue
3.141593 180 3.141593

When to Use Numeric Functions?

Advantages of Numeric Functions

Numeric functions play a crucial role in SQL for performing various mathematical operations.