Home
Unary prefix operators should not be repeated
Description
The rule "Unary prefix operators should not be repeated" states that when using unary prefix operators in PL/SQL code, the same operator should not be used multiple times in succession. For example, if the operator is "-", then "- -" should not be used. This is because the double operator would be redundant and could lead to confusion. Additionally, it could lead to errors in the code. Therefore, it is best practice to only use unary prefix operators once in succession.
Key Benefits
- Reduced complexity: Unary prefix operators should not be repeated to reduce complexity and improve readability of code.
- Consistency: Unary prefix operators should not be repeated to ensure consistency across the codebase.
- Avoid errors: Unary prefix operators should not be repeated to avoid errors and potential bugs.
Non-compliant Code Example
SELECT
NAME,
ADDRESS,
CREDIT_LIMIT
FROM
CUSTOMERS
WHERE NAME NOT IN (SELECT NAME FROM VENDOR WHERE NAME IS NOT NULL); --Non compliant code (Unary prefix operator repeated)
BEGIN IF NOT ( NOT foo = 5 ) THEN --Non compliant code (Unary prefix operator repeated) value := ++1; --Non compliant code (Unary prefix operator repeated) END IF; END;
Compliant Code Example
SELECT
NAME,
ADDRESS,
CREDIT_LIMIT
FROM
CUSTOMERS
INNER JOIN VENDOR
ON VENDOR.NAME IS NOT NULL AND VENDOR.NAME <> CUSTOMERS.NAME; --Compliant code
BEGIN IF foo = 5 THEN --Compliant code value := +1; --Compliant code END IF; END;