DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Oracle (http://www.daniweb.com/forums/forum129.html)
-   -   Subtracting a negative value (http://www.daniweb.com/forums/thread157017.html)

bondo Nov 13th, 2008 1:36 am
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?

debasisdas Nov 13th, 2008 10:15 am
Re: Subtracting a negative value
 
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;

bondo Nov 13th, 2008 5:15 pm
Re: Subtracting a negative value
 
That was my question. Why am I getting 3?

debasisdas Nov 15th, 2008 7:39 am
Re: Subtracting a negative value
 
the same block of pl/sql code never gives different output to different people on different machine.

like_to_learn Dec 9th, 2008 3:13 am
Re: Subtracting a negative value
 
Hai Bondo,
you will never get 3 for the above code..please check it once again...........................


All times are GMT -4. The time now is 8:01 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC