Monday, April 18, 2016

SQL : Arithmetic Expressions

Arithmetic Expressions

Add                      :               +
Subtract               :               -
Multiply                :               *
Divide                   :               /

Arithmetic Operators
You can use arithmetic operators in any clause of a SQL statement (except the FROM clause).
Note: With the DATE and TIMESTAMP data types, you can use the addition and subtraction
operators only.
Rules of Precedence
• Multiplication and division occur before addition and subtraction.
• Operators of the same priority are evaluated from left to right.
• Parentheses are used to override the default precedence or to clarify the statement.

Examples :

SELECT last_name, salary, salary + 300 FROM employees;
 In the above example , 300 is added to the salary of each employee in employees table.

SELECT last_name, salary, 12*(salary + 300) FROM employees;

In the above example , salary of each employee is added with 300 and finally multiplied by  12 to the annual salary of employee.  Here parentheses () is used to override default precedence.

Featured Post

Will the data from Oracle Database be lost after formatting the system in which it is installed?

So Someone asked me a question,  Will the data from Oracle Database be lost after formatting the system in which it is installed? Since the ...

Popular Posts