Home

NULL should not be compared directly

Description

    The rule "NULL should not be compared directly" in PL/SQL code means that when comparing two values, the comparison should not be done directly with the NULL value. Instead, the IS NULL or IS NOT NULL operators should be used. This is because the comparison of two NULL values will always return NULL, which may not be the desired result. Using the IS NULL or IS NOT NULL operators will ensure that the comparison is done correctly and that the expected result is returned.

Key Benefits

  • Ensures data integrity: NULL values are not compared directly, which helps ensure that data integrity is maintained.
  • Reduces errors: By not comparing NULL values directly, it reduces the chances of errors occurring when data is manipulated.
  • Improves performance: By not comparing NULL values directly, it improves the performance of queries and other operations.

 

Non-compliant Code Example

SELECT
    NAME,
    ADDRESS,
    CREDIT_LIMIT
FROM
    CUSTOMERS
WHERE
	CREDIT_LIMIT <> NULL;       --Non compliant code (Column compared directly with NULL)

Compliant Code Example

SELECT
    NAME,
    ADDRESS,
    CREDIT_LIMIT
FROM
    CUSTOMERS
WHERE
	CREDIT_LIMIT IS NOT NULL;       --Compliant code
Visual Expert 2024
 VEPLSQLRULE56