What is CEIL() in SQL?

The CEIL() function returns the nearest smallest integer that is greater than or equal to a number. Some database servers use the CEILING() function, which is equivalent to the CEIL() function. Figure 1 shows the mathematical representation of the CEIL() function.

Figure 1: Mathematical representation of CEIL() function

Syntax

CEIL(number)
CEILING(number)

Parameter

This function requires a number or a numeric value as a parameter.

Return Value

CEIL() returns the nearest smallest integer that is greater than or equal to a number sent as a parameter.

Example

/*example showing how to use CEIL(X)*/
-- positive number
select CEIL(3.13);
-- negative number
select CEIL(-2.78);

Now, consider another example in which the teacher wants to round up the marks of the students.

The figure below shows the student table, followed by the query that rounds up the marks.

Students

Student ID

Student Name

Student Marks

1

David

22.5

2

Luiss

20.14

3

Harvey

15.3

4

Lucy

25

5

Andrew

10.7

/*Query returns the marks of all the students after
applying CEIL() */
select studentID, studentName, CEIL(studentMarks) as studentMarks
from Students

Free Resources