Unary operators perform an operation on only one expression
of numeric data type.
Operator | Meaning |
+ (Positive) | Numeric value
is positive. |
- (Negative) | Numeric value
is negative. |
~ (Bitwise
NOT) | Returns the
ones complement of the number. |
+ (positive) and - (negative) operators can be used with any
expression of numberic datatype. ~ (bitwise not) operator can only be
used with any expression of integer datatype.
Examples of Unary Operators :
Examples of using + (positive) unary
operator in SELECT clause :
Example 1 : Using + (positive) unary
operator in SELECT clause
SELECT +20
Output
20
Above quey returns postive value only.
Example 2 : Using + (positive) unary operator for table fields in
SELECT clause
SELECT +UnitPrice
FROM Products
Output
UnitPrice
18.00
19.00
10.00
22.00
21.35
Examples of using - (negative) unary
operator in SELECT clause :
Example 1 : Using - (negative) unary
operator in SELECT clause
SELECT -20
Output
-20
Above quey returns negative value only.
Example 2 : Using - (negative) unary operator for table fields in
SELECT clause
SELECT -UnitPrice
FROM Products
Output
UnitPrice
-18.00
-19.00
-10.00
-22.00
-21.35