Arithmetic and Comparison Operators

Arithmetic Operators:
Ø  The Arithmetic operators can be used to create expressions on numbers and date data type columns.
Ø  The Arithmetic operators supported are:
o   Addition         à        +
o   Subtraction      à        -
o   Multiply          à        *
o   Divide             à        /
Ø  The Arithmetic operators can be used in any clause of a sql statement, except the from clause.
Ø  SQL * plus ignores blank spaces before and after the arithmetic operator. 
Ex:
  • Select Empno, Ename, Sal, Sal + 500 From Emp;
  • Select Empno, Ename, Sal, Sal – 1000 From Emp;
Operator Precedence:
Ø  Multiplication and Division take priority over Addition and Subtraction (*, /, +, -).
Ø  Operators of the same priority are evaluated from left to right.
Ø  To prioritize evaluation and to increase clarity parenthesis can be implemented.
Ex:
  • Select Empno, Ename, Sal, (12 * Sal) + 100 From Emp;
  • Select Empno, Ename, Sal, 12 * (Sal + 500) From Emp;
Comparison Operators:
Ø  Equality Operator                               à        =
Ø  Not Equality Operator                        à        < >,  !=, ^=
Ø  Greater Than Operator                        à        >
Ø  Less Than Operator                             à        <
Ø  Greater Than Equal to Operator         à        >=
Ø  Less Than Equal to Operator              à        <=
Ex:

  • Select Ename, Sal, Job From Emp Where Job = ’MANAGER’;
  • Select Ename, Hiredate, Deptno, Sal From Emp where Deptno < > 10;
  • Select Empno, Ename, Sal From Emp where Sal >= 3000;
  • Select Ename name, Sal basic, Sal * 12 Annual From Emp where sal * 12 > 60000;