954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Subtracting a negative value

Does anyone know how Oracle's PL/SQL handles subtraction with a negative number? Really what I need to know is, given the following: (NOTE: this is NOT the code I'm working with. It's just an example to give and idea of what I'm trying to do.)

DECLARE
number1 NUMBER;
number2 NUMBER;
number3 NUMBER;
BEGIN
number1 := 5;
number2 := -2;
number3 := number1 - number2;
END;
/


How do I get number3 to be 7, like math is supposed to work (5 - (-2) = 7)? I keep getting 3. Anyone?

bondo
Light Poster
45 posts since Apr 2007
Reputation Points: 11
Solved Threads: 0
 

but i am getting 7, how come you are getting 3 ?

DECLARE
number1 NUMBER;
number2 NUMBER;
number3 NUMBER;
BEGIN
number1 := 5;
number2 := -2;
number3 := number1 - number2;
dbms_output.put_line(number3);
END;
debasisdas
Posting Genius
6,870 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

That was my question. Why am I getting 3?

bondo
Light Poster
45 posts since Apr 2007
Reputation Points: 11
Solved Threads: 0
 

the same block of pl/sql code never gives different output to different people on different machine.

debasisdas
Posting Genius
6,870 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Hai Bondo,
you will never get 3 for the above code..please check it once again...........................

like_to_learn
Newbie Poster
9 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You