Howdy. Consider the following:
SQL> DECLARE
2 b1 BOOLEAN;
3 b2 BOOLEAN;
4 FUNCTION checkit RETURN BOOLEAN IS
5 BEGIN
6 dbms_output.put_line('inside checkit');
7 RETURN TRUE;
8 END checkit;
9
10 PROCEDURE outp(n VARCHAR2, p BOOLEAN) IS
11 BEGIN
12 IF p THEN
13 dbms_output.put_line(n||' is true');
14 ELSE
15 dbms_output.put_line(n||' is false');
16 END IF;
17 END;
18 BEGIN
19 b1 := TRUE OR checkit;
20 outp('b1',b1);
21 b2 := checkit OR TRUE;
22 outp('b2',b2);
23 END;
24 /
b1 is true
inside checkit
b2 is true
PL/SQL procedure successfully completed
SQL>
Notice that the results of the OR statements are order dependent. If I place the function call first, then the function is executed regardless of the value of the other term. It appears that an OR statement is evaluated left to right until a TRUE is obtained, at which point processing stops and the result it TRUE.
My question is, is this something I can rely on? Or could this behavior change in future releases of PL/SQL? If it could change, is there a way to force the function to be evaluated that I can rely on (without creating another variable and using a separate assignment statement)?