Home
CASE should be used for sequences of simple tests
Description
-
The CASE statement should be used for sequences of simple tests in PL/SQL code. This statement is used to evaluate a set of conditions and execute a block of code depending on the result of the evaluation. The CASE statement can be used to replace multiple IF statements, making the code more concise and easier to read.
Key Benefits
- Flexible: CASE allows for sequences of simple tests to be easily modified and adapted.
- Cost-effective: CASE reduces the cost of test development and maintenance.
- Efficient: CASE enables faster test development and execution.
- Reliable: CASE provides a reliable and consistent testing environment.
Non-compliant Code Example
DECLARE flag BOOLEAN := TRUE; BEGIN IF flag = FALSE THEN --Non compliant code (Case when clause should be used for sequence of tests) DBMS_OUTPUT.PUT_LINE('flag is false!'); ELSIF flag = TRUE THEN --Non compliant code (Case when clause should be used for sequence of tests) DBMS_OUTPUT.PUT_LINE('flag is true!'); END IF; END;
Compliant Code Example
DECLARE flag BOOLEAN := TRUE; BEGIN CASE WHEN NOT flag THEN --Compliant code DBMS_OUTPUT.PUT_LINE('flag is false!'); WHEN flag THEN --Compliant code DBMS_OUTPUT.PUT_LINE('flag is true!'); END CASE; END;