Hi , We all know about the AND function in Oracle PL/SQL . But only least know about the importance of the execution method. Let us start with the functionality of a AND function.
AND is a binary function which has two input and one output. The input and output will be either a Boolean TRUE / FALSE.
Above is the Truth table which explains the AND function. So if one of the input is FALSE the AND function will return FALSE no matter about the second input . This is the thing we normally remember about the AND function.
But we also have to remember the execution sequence of it. For example we can take the below cases. We have a AND between two functions which returns a Boolean value.
fun1 - will always insert a data into a table and returns TRUE
fun2 - does nothing and returns FALSE
Case 1 : fun1 AND fun2
Case 2: fun2 AND fun1
In both cases the result will be FALSE. But we have some difference in the execution.
Case 1 : fun1 AND fun2
In this case fun1 will be executed first , a data will be inserted into the table and TRUE will be returned. since the first input is TRUE, the AND will check the next input . In this case it checks the fun2 which returns FALSE. So the result will be FALSE.
Case2: fun2 AND fun1
In this case fun2 will be executed first , it returns FALSE. Since the first input is FALSE, the AND will not check (execute) the next input. Because as per AND logic if one input is FALSE it will always return FALSE , no matter about the second input.
Even thought both cases return FALSE , a data got inserted in Case 1 where as it doesn't happen in Case 2.
The main motive of the above writeup is to explain the execution sequence of a binary function in PL/SQL.
Oracle PL/SQL functions always follows a LEFT to RIGHT execution.