PLSQL | MOD Function
Last Updated :
18 Oct, 2019
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
.
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:
- Oracle 12c
- Oracle 11g
- Oracle 10g
- Oracle 9i
- 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.
Share your thoughts in the comments
Please Login to comment...