| 0 comments ]

Applying Arithmetical Operations In Select Statements :

1. Arithmetic expressions can be implemented through SELECT statement.
2. Arithmetic expressions can be implemented to

  • Modify the way the data is displayed.
  • Perform calculations.
  • Implement WHAT - IF scenarios.
3. An arithmetic expression can contain
  • Simple column names
  • Constant numeric values
  • Arithmetic operators.

Arithmetic Operators :
1. The arithmetic operators can be used to created expressions on NUMBER and DATE data.
2. The arithmetic operators supported are
  • Addition          +
  • Subtraction      -
  • Multiply           *
  • Divide              /
3. The arithmetic operators can be used in any clause of a sql statement. Except the FROM clause.
4. SQL * Plus ignores back spaces before and after the arithmetic operator.

SQL> SELECT Empno, Ename, Sal, Sal+500 from Emp ;
 
Operator Precedence :
  • Multiplication and division take priority over addition and subtractions (* ,/, +, -).
  • Operators of the same prority and evaluated from left to right.
  • To prioritize evaluation and to increase clarity parenthesis can be implemented.

SQL> SELECT Empno,Ename,Sal, 12*sal+100 FROM Emp;
SQL> SELECT Empno,Ename,Sal, (12*sal)+100 FROM Emp;
SQL> SELECT Empno,Ename,Sal, 12*(sal+100) FROM Emp;
Note : According to operator precedence, the evaluation of an expression can be changed.

0 comments

AddThis

| More
Widget By Devils Workshop