SAP HANA Reference
Operators

You can perform arithmetic operations in expressions by using operators. Operators can be used for calculation, value comparison or to assign values.

Unary and Binary Operators

Table 10. Unary and binary operators
Operator Operation Format Description
Unary A unary operator applies to one operand or a single value expression. operator operand unary plus operator(+)

unary negation operator(-)

logical negation(NOT)

Binary Binary A binary operator applies to two operands or two value expressions. operand1 operator operand2 multiplicative operators ( *, / )

additive operators ( +,- )

comparison operators
( =,!=,<,>,<=,>=)

logical operators ( AND, OR )

Operator Precedence

An expression can use several operators. If the number of operators is greater than one then the SAP HANA Database will evaluate them in order of operator precedence. You can change the order of evaluation by using parentheses, as expressions contained within parentheses are always evaluated first.

If parentheses are not used, the operators have the precedence indicated by the table below. Please note, the SAP HANA Database will evaluate operators with equal precedence from left to right within an expression.

Table 11. SQL operator precedence
PrecedenceOperatorOperation
Highest () parentheses
+, - unary positive and negative operation
*, / multiplication, division
+, - addition, subtraction
|| concatenation
=, !=, <, >, <=, >=, IS NULL, LIKE, BETWEEN comparsion
NOT logical negation
AND conjunction
Lowest OR disjunction

Arithmetic Operators

You use arithmetic operators to perform mathematical operations such as adding, subtracting, multiplying, dividing and negation of numeric values.

Table 12. Arithmetic operators
Operator Description
-<expression> Negation. If the expression is the NULL value, the result is NULL.
<expression> + <expression> Addition. If either expression is the NULL value, the result is NULL.
<expression> - <expression> Subtraction. If either expression is the NULL value, the result is NULL.
<expression> * <expression> Multiplication. If either expression is NULL, the result is NULL.
<expression> / <expression> Division. If either expression is NULL, or if the second expression is 0, an error is returned.

String Operators

A concatenation operator combines two items such as strings, expressions or constants into one.

Table 13. Concatenation operators
Operator Description
<expression> || <expression> String concatenation (two vertical bars).
If either string is NULL, it returns NULL.

For VARCHAR or NVARCHAR type strings, leading or trailing spaces are kept. If either string is of data type NVARCHAR, the result has data type NVARCHAR and is limited to 5000 characters. The maximum length for VARCHAR concatenation is also limited to 5000 characters.

Comparsion Operators

Syntax:

<comparison_operation> ::= <expression1> <comparison_operator> <expression2> 


Table 14. Comparison operators
Operator Description Example
= Equal to SELECT * FROM students WHERE id = 25;
> Greater than SELECT * FROM students WHERE id > 25;
< Less than SELECT * FROM students WHERE id < 25;
>= Greater than or equal to SELECT * FROM students WHERE id >= 25;
<= Less than or equal to SELECT * FROM students WHERE id <= 25;
!=, <> Not equal SELECT * FROM students WHERE id != 25;
SELECT * FROM students WHERE id <> 25;

Logical Operators

Search conditions can be combined using AND or OR operators. You can also negate them using the NOT operator.

Table 15. Logical operators
Operator Syntax Description
AND WHERE condition1 AND condition2 When using AND, the combined condition is TRUE if both conditions are TRUE, FALSE if either condition is FALSE, and UNKNOWN otherwise.
OR WHERE condition1 OR condition2 When using OR, the combined condition is TRUE if either condition is TRUE, FALSE if both conditions are FALSE, and UNKNOWN otherwise.
NOT WHERE NOT condition The NOT operator is placed before a condition to negate the condition. The NOT condition is TRUE if condition is FALSE, FALSE if condition is TRUE, and UNKNOWN if condition is UNKNOWN.

Set Operators

The operators described in this section perform set operations on the results of two or more queries.

Table 16. Set operators
Operator Returned Value
UNION Combines the results of two or more select statements or query expressions
UNION ALL Combines the results of two or more select statements or query expressions, including all duplicate rows.
INTERSECT Combines the results of two or more select statements or query expressions, and returns all common rows.
EXCEPT Takes output from the first query and then removes rows selected by the second query.