06 July, 2011

Three-Valued Logic

SA,
Three-Valued logic mean a  boolean variable have three values( true ,false and intermediate value that isn't false nor true).
You can read in details about that topic at Wikipedia.
But at that article I am focusing in how to use Three-Valued logic in PLSQL and its effecting of code control statements.



First of all at plsql any operation or comparsion with null value result to null value.

For example

 DECLARE  
   x  BOOLEAN;  
 BEGIN  
   IF x THEN  
     --true value  
   ELSE  
     --false value  
   END IF;  
 END;  

In the previous code the control will execute the code in ELSE however that is logical false because value of X variable is null nor "FALSE".
So every developer must take care about three-value logic and the correct code must be as the following

 DECLARE  
  x  BOOLEAN;  
   
 BEGIN  
  IF x is null THEN  
    --null value  
  elsif x then  
    --true value  
  ELSE  
    --false value  
  END IF;  
   
 END;   

I hope that my post is helpful and useful.
If you have any question, Feel free to ask at email mahmoud_ahmed01@yahoo.com
Mahmoud Ahmed

No comments:

Post a Comment

ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope. There are five scopes in ADF (Application, Request, Session, View and PageFl...