Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Thursday 14 March 2024

CEIL Function in MariaDB

The CEIL function in MariaDB is used to return the smallest integer value that is greater than or equal to a given number. It rounds up a number to the nearest integer.


Here's the syntax for the `CEIL` function:


CEIL(number)


- number: The number or expression to be rounded up.


Example:

SELECT CEIL(4.2);

Output:

5


In this example, CEIL returns the smallest integer value that is greater than or equal to 4.2, which is 5.


Here are some key points to note about the CEIL function in MariaDB:


1. Equivalent to ROUNDUP: The CEIL function is equivalent to the `ROUNDUP` function and rounds up a number to the nearest integer greater than or equal to the given number.


2. Handling Negative Numbers: If the argument passed to CEIL is a negative number, it rounds up towards zero, producing a more positive integer.


3. Data Type Preservation: The data type of the result is the same as the data type of the argument passed to the function.


4. Mathematical Precision: CEIL operates with mathematical precision and does not round to a specific number of decimal places. It simply rounds up to the nearest integer.


5. Behavior with NULL: If the argument passed to CEIL is NULL, the function returns NULL.


The CEIL function in MariaDB is useful when you need to round up numeric values to the nearest integer, ensuring that calculations or comparisons are performed accurately.


Here are few more examples:-


1. Rounding up a positive decimal number:

SELECT CEIL(4.2);

Output:

5


2. Rounding up a negative decimal number:

SELECT CEIL(-3.8);

Output:

-3


3. Rounding up a positive integer:

SELECT CEIL(7);

Output:

7


4. Rounding up a NULL value:

SELECT CEIL(NULL);

Output:

NULL


These examples illustrate how the CEIL function works with different types of input values, including positive and negative decimal numbers, integers, and NULL values.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.