Re: Trigger Question

From: Jonathan Gennick <gennick_at_worldnet.att.net>
Date: 1998/01/03
Message-ID: <68k3im$29i_at_mtinsc03.worldnet.att.net>#1/1


On Tue, 30 Dec 1997 20:44:03 -0500, Charles Dunaway <cdunaway_at_navpoint.com> wrote:

> if :old.name <> :new.name then

 <snip>
>This appears to work sporadically, but not consistently, for example, if
>the new value is a null string nothing happens.

In three-valued logic, a null equates to an "unknown" value. Is :old.name different from that unknown value? The answer to that question is unknown because the value of :new.name is unknown. Thus the boolean expression evaluetes to UNKNOWN. The IF statement will only execute if the boolean expression evaluets to TRUE.

The following PL/SQL block illustrates my point:

SQL> set serveroutput on
SQL> 
SQL> declare 

  2 x number;
  3 begin
  4 x := null;
  5 if 2 = x then
  6 dbms_output.put_line('2 = x');
  7 elsif 2 <> x then
  8 dbms_output.put_line('2 <> x');   9 else
 10 dbms_output.put_line('the unknown case');  11 end if;
 12 end;
 13 /
the unknown case

PL/SQL procedure successfully completed.

You have to watch those nulls<g>. Received on Sat Jan 03 1998 - 00:00:00 CET

Original text of this message