// math reference

SQL CEILING function

Rounds a number up to the nearest integer, toward positive infinity: CEILING(2.1) is 3 and CEILING(-2.1) is -2.

Kategorie
Math
Returns
same type as the input
In this category
11 of 82

Syntax

CEILING(number)
CEIL(number)

Each block is a separate form. The support table and the examples show which engine takes which.

Engine-Unterstützung

EngineSupportNotizen
SQL Server Ja Only CEILING; CEIL is not a T-SQL function
PostgreSQL Ja CEIL and CEILING are both built in
MySQL Ja CEIL and CEILING are both built in
SQLite Ja Requires SQLite 3.35+ with the math functions built in; both spellings exist and return REAL for REAL input
Oracle Ja Only CEIL; there is no CEILING keyword

Beispiele

SQL Server

SELECT CEILING(2.1) AS up, CEILING(-2.1) AS neg_up;  -- 3, -2

Oracle

SELECT CEIL(2.1) AS up, CEIL(-2.1) AS neg_up FROM dual;  -- 3, -2

PostgreSQL

SELECT CEIL(total_pages / 500.0) AS page_batches
FROM print_jobs;

SQL Server

SELECT CEILING(disk_gb / 100.0) AS billed_units
FROM usage;

Gut zu wissen

  • CEILING moves toward positive infinity, so CEILING(-2.1) is -2, not -3. FLOOR(-2.1) is -3.
  • The result keeps the input's type family: CEILING of a decimal is a decimal with scale 0, CEILING of a float is a float. SQLite returns 3.0, not 3, for REAL input.
  • Integer division eats the rounding: CEILING(7/2) on integer columns is CEILING(3) = 3, not 4. Compute CEILING(7/2.0).

Questions about CEILING

Is it CEIL or CEILING?

Both names work on PostgreSQL, MySQL and SQLite. SQL Server only accepts CEILING and Oracle only accepts CEIL, so no single spelling runs on all five.

Why does CEILING(7/2) return 3 instead of 4?

7/2 is integer division and evaluates to 3 before CEILING sees it. Force decimal division with 7/2.0, or CAST one operand, then CEILING gets 3.5 and returns 4.

What does CEILING return for a negative number?

The next integer toward positive infinity: CEILING(-2.1) is -2. If you want -3 you are thinking of FLOOR.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.