Arithmetic operators are used to perform arithmetic operations like addition, subtraction, multiplication and division. However the operators + ,- and ~ can also be used as unary operators to decide if a number is positive or negative. But we can have fun with the usage of these operators.
The following statement
select -4,+4
returns –4 and 4 as result
Now execute the following statement
select -+-+4
The result is 4. But you may think it will give some syntax error
Now execute the following which also produces the result 4
select -+-+-+(-4)
select -+-+-+-+++4
Do you know why the following code produces -4 as result?
select -++-+-+-+++-4
Now execute the following and see the result
select -(-(-4))
select -(-(-(-4)))
The result is -4 and 4
The following statement returns -4 as the result
select +++++++++++++++++++++++++++++++++++++++++++++-4
So from these it is very clear that when there are even number of uniary minus the result is positive otherwise the result is negative
This is also true for unary ~ (Bitwise NOT)
select ~4
select ~~4
select ~~~~4
The results are -5,4 and 4 respectively.
The same can be applied to column of a table too. Cosider the following code
select
number as positive1, -number as negative1, +-+-number as positive2, -+-+-+(-(-number)) as negative2
from
(
select 1 as number union all
select 2 as number union all
select 3 as number
) as t
positive1 negative1 positive2 negative2
----------- ----------- ----------- -----------
1 -1 1 -1
2 -2 2 -2
3 -3 3 -3
I do not see the practical usage of these leading unary + and - however for complex arithmetic calculation that involve in many additions and subtractions you can find out how the result is positive or negative using the above examples