while loop [message #556428] |
Mon, 04 June 2012 04:50  |
Roger22
Messages: 98 Registered: April 2009 Location: Brasov, ROMANIA
|
Member |
|
|
Hi,
I have the code:
declare
subtype my_type is pls_integer range 0..1000;
a my_type;
b my_type;
c my_type;
begin
-- let's say i initialize a with 900, b=800 and c=1000
a:=a-1;
b:=b-1;
c:=c-1;
exception
when others then
raise_application_error(-20114, 'Out of limit!');
end;
/
My question is how can i raise that error, only if ALL these 3 variables are outside of limit? so, first if b will be 0 and i try do decrement, if there are any other variables to decrement(in legal range), i should not raise the error (but only if all of them become outside of limit).
Thanks!
[Updated on: Mon, 04 June 2012 04:54] Report message to a moderator
|
|
|
|
Re: while loop [message #556440 is a reply to message #556434] |
Mon, 04 June 2012 05:38  |
_jum
Messages: 577 Registered: February 2008
|
Senior Member |
|
|
Only trap the correct exception "VALUE_ERROR" and do as @Michel said.
If You have to check underflow/overflow seperate, you could use least/greatest as in the example:
SET SERVEROUTPUT ON SIZE 900000;
declare
subtype my_type is pls_integer range 0..1000;
a pls_integer;
b pls_integer;
c pls_integer;
d my_type;
begin
-- let's say i initialize a with 900, b=800 and c=1000
a := 0;
b := 0;
c := 1;
a := a-1;
b := b-1;
c := c-1;
-- no underflow of c
d := greatest(a,b,c);
a := a-1;
b := b-1;
c := c-1;
-- now underflow
d := greatest(a,b,c);
exception when VALUE_ERROR
then raise_application_error(-20114, 'Out of limit! a='||a||' b='||b||' c='||c);
end;
ORA-20114: Out of limit! a=-2 b=-2 c=-1
|
|
|