Oracle Number Function - Oracle/PLSQL MOD Function






This Oracle tutorial explains how to use the Oracle/PLSQL MOD function.

The Oracle/PLSQL MOD function returns the remainder of m divided by n.

Mod(N,M) returns the remainder of N/M where both N And M are integers.

Syntax

The syntax for the Oracle/PLSQL MOD function is:

MOD( m, n )

The MOD is calculated as:m - n * floor(m/n)

MOD function returns m if n is 0. The MOD function uses the FLOOR function in its formula.

Example


select mod(3,2) from dual;

create table TestTable(
      ID                 VARCHAR2(4 BYTE)         NOT NULL,
      MyNumber           Number(8,2)-- w  ww  .  j  av  a 2 s  . c  om
    );

insert into TestTable (ID, MyNumber)values('1',12);
insert into TestTable (ID, MyNumber)values('1',1);
insert into TestTable (ID, MyNumber)values('1',1.1);

SQL> select myNumber from testTable;

  MYNUMBER
----------
        12
         1
       1.1

SQL> select mod(myNumber,2) from testTable;

MOD(MYNUMBER,2)
---------------
              0
              1
            1.1

SQL>