MySQL CEILING() function
In this context, we will learn how we can use the MySQL CEILING () function with proper syntax and good examples.
Introduction of MySQL CEILING () function
The CEILING() function accepts the inputs by user and give back the smallest integer value that is greater than or equal to that mentioned number.
For instance, if a mentioned number is 5.7, the CEILING() function will give back the integer value of 6, which is greater than 5.7, or on the other hand, if a specified integer is 7, then the function will give back 7 that is equal to 7.
Important characteristics of MySQL CEILING() function:
- The prime use of this function is to find the smallest integer value which is greater than or the same as the mentioned integer.
- A single parameter is accepted by this function.
- The parameter which is accepted by this function can be a numeric value of an integer or float data type.
Syntax of the MySQL CEILING() function:
CEILING ( num );
Parameter or argument used in MySQL CEILING function:
Only one parameter is accepted by this method:
Num- This is the mentioned numeric value.
Returns- It will return the smallest integer value that is greater than or equal to a mentioned number.
Some examples of MySQL CEILING function:
Example: 1
Here, we will get the smallest integer, 1, which is greater than the mentioned numeric value 0.7.
SELECT CEILING( 0.7 );
Now the output is :
1
Example: 2
Here, we will get the smallest number, 4, which is greater than the mentioned numeric value “ 3.141592635 ”, which is the value of pi.
Here the function of pi returns the value of pi, and after that, the function CEILING function takes the pi value as an argument and gives us the output as 4.
SELECT CEILING( pi());
Now the output is:
4
Example: 3
Here, we will get the number 15, which is the same as the given back random value among 7 and 20.
A random number between 7 and 20 will be returned by the floor function, and after that, the CEILING function() takes the returned value as an argument and will return the same number, 15.
SELECT CEILING(floor( 7 + rand () * ( 20 - 7 + 1)));
Now the output is:
14
Example: 4
Here, we will get the smallest integer value, 545, which is greater than the specified numeric value “544.7”, which is the absolute value of “-544.7” that is returned by the abs() function.
The CEILING() function takes the value “544.7” as the argument and gives back the value “545”.
SELECT CEILING(abs( -544.7 ));
Now the output is:
545
Summary:
In this context, we have learned how the function is applied to return the smallest integer value that is greater than or equal to that mentioned number.