Friday, January 28, 2011

FLOOR and CEIL

FLOOR returns the smallest integer less than or equal to the expression in brackets. CEIL returns the smallest integer greater than or equal to the expression in brackets. I tried to catch them out but failed:

SQL> select floor(-3.2), ceil(-3.2)
  2  from dual;

FLOOR(-3.2) CEIL(-3.2)
----------- ----------
         -4         -3

1 row selected.

SQL> select floor(-0), ceil(-0)
  2  from dual;

 FLOOR(-0)   CEIL(-0)
---------- ----------
         0          0

1 row selected.

SQL> select floor(0/0) from dual;
select floor(0/0) from dual
              *
ERROR at line 1:
ORA-01476: divisor is equal to zero
  
SQL> select ceil(0/0) from dual;
select ceil(0/0) from dual
             *
ERROR at line 1:
ORA-01476: divisor is equal to zero
  
SQL> select floor(0/1), ceil(0/1)
  2  from dual;

FLOOR(0/1)  CEIL(0/1)
---------- ----------
         0          0

1 row selected.

SQL> select floor(2.5*2.5), ceil(2.5*2.5)
  2  from dual;

FLOOR(2.5*2.5) CEIL(2.5*2.5)
-------------- -------------
             6             7

1 row selected.

SQL> select floor(12.0), ceil(12.0)
  2  from dual;

FLOOR(12.0) CEIL(12.0)
----------- ----------
         12         12

1 row selected.

SQL> select floor(14.6), ceil(14.6)
  2  from dual;

FLOOR(14.6) CEIL(14.6)
----------- ----------
         14         15

1 row selected.

SQL>

No comments:

Post a Comment