Open In App

PLSQL | MOD Function

Last Updated : 18 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report
The MOD function is an inbuilt function in PLSQL which is used to return the remainder when a is divided by b. Its formula is m - n * \left\lfloor\dfrac{m}{n}\right\rfloor. Syntax:
MOD(a, b)
Parameters Used: This function accepts two parameters a and b. This function gives remainder as the output when the input number a is divided by b. Return Value: This function returns the remainder when a is divided by b. Supported Versions of Oracle/PLSQL is given below:
  1. Oracle 12c
  2. Oracle 11g
  3. Oracle 10g
  4. Oracle 9i
  5. Oracle 8i
Let’s see some examples which illustrate the MOD function: Example-1:
DECLARE 
   Test_Number number1 := 15;
   Test_Number number2 := 4;
   
BEGIN 
   dbms_output.put_line(MOD(Test_Number number1, 
                            Test_Number number2)); 
   
END;  
Output:
3
In the above example, when the numeric value 15 is divided by 4 then it returns the remainder of 3 as output. Example-2:
DECLARE 
   Test_Number number1 := 15;
   Test_Number number2 := 0;
   
BEGIN 
   dbms_output.put_line(MOD(Test_Number number1, 
                            Test_Number number2)); 
   
END; 
Output:
15
In the above example, when the numeric value 15 is divided by 0 then it returns the remainder of 15 as output. Example-3:
DECLARE 
   Test_Number number1 := 11.6;
   Test_Number number2 := 2.1;
   
BEGIN 
   dbms_output.put_line(MOD(Test_Number number1, 
                            Test_Number number2)); 
   
END; 
Output:
1.1
In the above example, when the numeric value 11.6 is divided by 2.1 then it returns the remainder of 1.1 as output. Advantage: This function is used to find the remainder when a is divided by b.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads