Header Ads

Header ADS

Arithmetic Expressions

Arithmetic Expressions in Oracle SQL

Topic introduction: Often we need to calculate to show data by SQL Query, so arithmetic expression is most important to calculate on Oracle SQL statement. 


Arithmetic Operators: The slide lists the arithmetic operators that are available in SQL. 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.


Using Arithmetic Operators

SELECT last_name, salary, salary + 300
FROM employees;




The example in the slide demonstrates the use of the addition operator to calculate a salary increase of $500 for all employees. It also showcases a 'salary+500' column in the output. It's important to note that the resulting calculated column, 'salary+500,' is not an additional column in the EMPLOYEES table; it is purely for display purposes. By default, the name of a new column is derived from the calculation that generated it, in this case, 'salary+300.


Operator Precedence

In arithmetic expressions, the evaluation follows the rules of precedence:

01. Multiplication and division take precedence over addition and subtraction.
02. When operators in an expression have the same priority, they are evaluated from left to right.
03. Parentheses can be used to explicitly specify the order of evaluation or to clarify the expression.


Note: The Oracle server ignores blank spaces before and after the arithmetic operator.

No comments

Theme images by Deejpilot. Powered by Blogger.