devdar
devdar

Reputation: 5654

Oracle Forms 6i Comparing Fields

I have a form with two fields which are type Char 128 each i am trying to compare the contents of these fields. However i am not getting a proper comparison done. When both fields have the same data it is still saying both fields do not match.

Begin

IF(LTRIM(RTRIM(:field1)) = LTRIM(RTRIM(:field2)))THEN
 Show_Message('Fields Match');
ELSE
 Show_Message('Fields DO NOT Match');
END IF;

End;

Upvotes: 1

Views: 1208

Answers (2)

Peter Å
Peter Å

Reputation: 1319

The problem is as already stated that in Oracle NULL is not equal to NULL. In Oracle a comparison with NULL will always be false. You can work around this with using NVL but in this case I should prefer to instead use IS NULL like something like this:

Begin

  IF (LTRIM(RTRIM(:field1)) = LTRIM(RTRIM(:field2))) 
  OR (:field1 IS NULL AND :field2 IS NULL) THEN
   Show_Message('Fields Match');

  ELSE
   Show_Message('Fields DO NOT Match');

  END IF;

End;

Upvotes: 3

Sathyajith Bhat
Sathyajith Bhat

Reputation: 21851

If the form fields are NULL, then the equality comparison won't work. You can use nvl function to substitute NULLs

Begin

IF(LTRIM(RTRIM(nvl(:field1,'*@#')) = LTRIM(RTRIM(nvl(:field2,'*@#'))))THEN
 Show_Message('Fields Match');
ELSE
 Show_Message('Fields DO NOT Match');
END IF;

End;

Upvotes: 2

Related Questions