MariaDB CEIL() Explained

In MariaDB, CEIL() is a built-in numeric function that returns the smallest integer value not less than its argument.

CEIL() is a synonym for CEILING().

Syntax

The syntax goes like this:

CEIL(X)

Where X is the value to apply the operation to.

Example

Here’s an example:

SELECT CEIL(3.1478);

Result:

+--------------+
| CEIL(3.1478) |
+--------------+
|            4 |
+--------------+

Passing a negative value produces the following result:

SELECT CEIL(-3.1478);

Result:

+---------------+
| CEIL(-3.1478) |
+---------------+
|            -3 |
+---------------+

Compared to ROUND()

The CEIL() function is different to the ROUND() function. The ROUND() function would round the number down in some instances, whereas CEIL() always returns the smallest integer value not less than its argument.

SELECT 
    CEIL(3.1478),
    ROUND(3.1478);

Result:

+--------------+---------------+
| CEIL(3.1478) | ROUND(3.1478) |
+--------------+---------------+
|            4 |             3 |
+--------------+---------------+

Also, ROUND() allows us to specify the number of decimal places to round to:

SELECT 
    CEIL(3.1478),
    ROUND(3.1478, 2);

Result:

+--------------+------------------+
| CEIL(3.1478) | ROUND(3.1478, 2) |
+--------------+------------------+
|            4 |             3.15 |
+--------------+------------------+

Non-Numeric Arguments

Here’s what happens when we provide a non-numeric argument:

SELECT CEIL('Three');

Result:

+---------------+
| CEIL('Three') |
+---------------+
|             0 |
+---------------+
1 row in set, 1 warning (0.000 sec)

Let’s check the warning:

SHOW WARNINGS;

Result:

+---------+------+-------------------------------------------+
| Level   | Code | Message                                   |
+---------+------+-------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'Three' |
+---------+------+-------------------------------------------+

Missing Arguments

Calling CEIL() without an argument results in an error:

SELECT CEIL();

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CEIL'