Home » SQL & PL/SQL » SQL & PL/SQL » What is Unknown in logical operator
What is Unknown in logical operator [message #659414] Mon, 16 January 2017 04:30 Go to next message
asliyanage
Messages: 60
Registered: January 2017
Member
I found that logical operator(AND,OR,NOT) can have state unknown(True,False,Unknown). I understand the true and false. But what is the Unknown state. When is the these logical operator have unknown state?
Re: What is Unknown in logical operator [message #659418 is a reply to message #659414] Mon, 16 January 2017 04:46 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

UNKNOWN is when the result of operation returns NULL.
In other words, UNKNOWN is the name of NULL in logical operations.

Re: What is Unknown in logical operator [message #659419 is a reply to message #659414] Mon, 16 January 2017 04:47 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
In oracle, you get unknown when one or more of the values you're comparing is null:
declare

l varchar2(1);
m varchar2(1) := 'A';
bool boolean;

begin

  bool := (l=m);
  
  IF bool = TRUE THEN
  
    dbms_output.put_line('comparsion is true');
    
  ELSIF bool = FALSE THEN
  
    dbms_output.put_line('comparsion is false');
    
  ELSE
  
    dbms_output.put_line('comparsion is unknown');
    
  END IF;
  
  
  --With AND
  bool := (l=m) AND 1=1;
  
  IF bool = TRUE THEN
  
    dbms_output.put_line('AND comparsion is true');
    
  ELSIF bool = FALSE THEN
  
    dbms_output.put_line('AND comparsion is false');
    
  ELSE
  
    dbms_output.put_line('AND comparsion is unknown');
    
  END IF;
  
  IF NOT bool THEN
    dbms_output.put_line('NOT bool');
  ELSE
    dbms_output.put_line('NOT NOT bool, because it''s not false');
  END IF;
  
--  WITH OR
  bool := (l=m) OR 1=1;
  
  IF bool = TRUE THEN
  
    dbms_output.put_line('OR comparsion is true');
    
  ELSIF bool = FALSE THEN
  
    dbms_output.put_line('OR comparsion is false');
    
  ELSE
  
    dbms_output.put_line('OR comparsion is unknown');
    
  END IF;

  
end;

comparsion is unknown
AND comparsion is unknown
NOT NOT bool, because it's not false
OR comparsion is true

PL/SQL procedure successfully completed.
Re: What is Unknown in logical operator [message #660274 is a reply to message #659419] Tue, 14 February 2017 01:42 Go to previous messageGo to next message
asliyanage
Messages: 60
Registered: January 2017
Member
Thanks everyone
Re: What is Unknown in logical operator [message #660278 is a reply to message #660274] Tue, 14 February 2017 01:53 Go to previous message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

This is a little bit short when this "thank" is asked to you and given by you just to get another help.
Feedback means you tell what you learn from this so we know if you clearly understood and future comers will be helped just reading your final post.

Previous Topic: PL/SQL: numeric or value error: character string buffer too small
Next Topic: How to identify one row from duplicate rows
Goto Forum:
  


Current Time: Tue Apr 23 21:48:42 CDT 2024