Home

Boolean literals should not be redundant

Description

    The "Boolean literals should not be redundant" rule states that when writing PL/SQL code, Boolean literals should not be used redundantly. This means that if a Boolean literal is already established, it should not be repeated. This rule is important for writing efficient and effective code, as repeating Boolean literals can lead to confusion and errors.

Key Benefits

  • Eliminates Redundancy: Boolean literals should not be redundant, as this helps to reduce the amount of code that needs to be written and maintained.
  • Improves Readability: Boolean literals should not be redundant, as this makes the code easier to read and understand.
  • Increases Efficiency: Boolean literals should not be redundant, as this helps to optimize the code and make it run faster.
  • Reduces Errors: Boolean literals should not be redundant, as this helps to reduce the chances of errors occurring in the code.

 

Non-compliant Code Example

DECLARE flag BOOLEAN := TRUE;
BEGIN
  IF flag = FALSE THEN  --Non compliant code (Boolean literals is redundant)
    DBMS_OUTPUT.PUT_LINE('flag is false!');
  ELSIF flag = TRUE THEN  --Non compliant code (Boolean literals is redundant)
    DBMS_OUTPUT.PUT_LINE('flag is true!');
  END IF;
END;

Compliant Code Example

DECLARE flag BOOLEAN := TRUE;
BEGIN
  IF NOT flag THEN   --Compliant code
    DBMS_OUTPUT.PUT_LINE('flag is false!');
  ELSIF flag THEN     --Compliant code
    DBMS_OUTPUT.PUT_LINE('flag is true!');
  END IF;
END;
Visual Expert 2024
 VEPLSQLRULE128