In Mathematics, basic operators (+, -, /, *) helps to add, subtract, divide or multiply two numbers. In oracle, they are arithmetic operators that perform an arithmetic operation between 2 numbers.
List of Arithmetic Operators
- + Operator: Used to add 2 numbers
- - Operator: Used to subtract numbers
- * Operator: Used to multiply numbers.
- / Operator: Used to divide numbers.
- MOD Operator: It is a special kind of Operator. For further reference, click here.
1. Arithmetic Operations on Numeric Values
Syntax
If it is between 2 numbers:
n1 Operator n2
where n1 and n2 are different numbers.
Suppose we add a column Marks in a Stu table. we have the table stu shown below:
Stu | ||||
Name | Section | Roll_No | Subject | Marks_Outof_100 |
Radha | B | 180 | Science | 56 |
Shruti | B | 16 | Science | 40 |
Sneha | B | 17 | Science | 20 |
Akshita | C | 1 | Commerce | 80 |
Bhoomika | C | 16 | Humanities | 78 |
To insert Values into the Table, click here.
Example 1: Now, we want to know marks of Students by adding 10 Marks more to the existing marks:
SELECT Name, Marks+10 FROM Stu;
Example 2: Same as above, we can use other mentioned operators ie. -,*,/ & %:
SELECT Name, Marks-10, Marks/10,Marks*10 FROM Stu;
Output:
Example 3: We want to first multiply the marks by 100 and divide the result by 10.
SELECT Name, (Marks*100)/10 FROM Stu;
Output
2. Arithmetic Operations on Date Values
We can only perform + & - Operator when it comes to Date. No * and / take place while working with Dates.
For example, we created another Variable ADD_Date that represents the Admission Date of a student in the Stu table.
Refer to the table given below:-
Example 1: we want to perform + & - Operator with Add_Date:
SELECT ADD_Date+5 from Stu;
Output:
Example 2:
SELECT ADD_Date-5 from Stu;
NOTE:
- We cannot perform arithmetic operations with strings.
- Any calculation performed on NULL values will return NULL.