Skip to content
Related Articles

Related Articles

Improve Article

CEILING() Function in MySQL

  • Last Updated : 21 Jan, 2021
Geek Week

CEILING() function :
This function in MySQL is used to return the smallest integer value that is greater than or equal to a specified number. For example, if the specified number is 4.6, this function will return the integer value of 5 that is greater than 4.6 or if a specified number is 5, this function will return 5 that is equal to 5.

Features :

  • This function is used to find the smallest integer value that is greater than or equal to a specified number.
  • This function accepts a single parameter.
  • The accepted parameter is a numeric value of integer or float data type.

Syntax :

CEILING(number)

Parameter :
This method accepts a parameter as given below –

  • number – Specified numeric value.

Returns : It returns the smallest integer value that is greater than or equal to a specified number.



Example-1 :
Getting the smallest number 1 that is greater than the specified numeric value 0.8.

SELECT CEILING(0.8);

Output :

1

Example-2 :
Getting the smallest number 4 that is greater than the specified numeric value “3.1415926535897931” which is the value of pi. Here the value of pi has been returned from the function PI() and then the function CEILING() function takes this value of pi as an argument and returned the value 4.

SELECT CEILING(PI());

Output :

4

Example-3 :
Getting the number 14 that is same as the returned random value between 6 and 20. Here the FLOOR() function will return a random number between 6 and 20 then the function CEILING() takes this returned value as parameter and returns the same number 14.

SELECT CEILING(FLOOR(6 + RAND()*(20 - 6 + 1)));

Output :

14

Example-4 :
Getting the smallest number 433 that is greater than the specified numeric value “432.8” which is the absolute value of “-432.8” returned by the function ABS(). The CEILING() function takes the value “432.8” as the parameter and returns the value “433”.

SELECT CEILING(ABS(-432.8));

Output :

433

Application :
This function is used to return the smallest integer value that is greater than or equal to a specified number.
 

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

My Personal Notes arrow_drop_up
Recommended Articles
Page :