PLSQL | MOD Function

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.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.