|Re: what is short circuit evaluation [message #238281 is a reply to message #238278]
||Thu, 17 May 2007 05:23
Registered: February 2007
When evaluating a logical expression, PL/SQL uses short-circuit evaluation.
That is, PL/SQL stops evaluating the expression as soon as the result can be determined.
This lets you write expressions that might otherwise cause an error.
Consider the following OR expression:
on_hand INTEGER := 0;
on_order INTEGER := 100;
-- Does not cause divide-by-zero error; evaluation stops after 1st expr.
IF (on_hand = 0) OR ((on_order / on_hand) < 5) THEN
dbms_output.put_line('There are no more widgets left!');
When the value of on_hand is zero,
the left operand yields TRUE, so
PL/SQL does not evaluate the right operand.
If PL/SQL evaluated both operands before applying the
OR operator, the right operand would cause a
division by zero error
i got the above from here
[Updated on: Thu, 17 May 2007 05:25]
Report message to a moderator