Home
Dead stores should be removed
Description
The rule "Dead stores should be removed" states that any variables that are assigned a value but never used should be removed from the PL/SQL code. This is because any variables that are never used waste memory and can slow down the code execution. Removing these variables can help to improve the performance of the code. Additionally, it can help to reduce the complexity of the code and make it easier to read and understand.
Key Benefits
- Reduced clutter: Removing dead stores eliminates unnecessary clutter in the code, making it easier to read and maintain.
- Improved performance: Removing dead stores can improve the performance of the code by reducing the number of memory accesses.
- Reduced memory usage: Removing dead stores can reduce the amount of memory used by the program, freeing up resources for other tasks.
Non-compliant Code Example
BEGIN IF price > 0 AND price < 500000 THEN CarLevel := 'Low Model'; --Non compliant code (Dead stores should be removed) ELSIF price >= 500000 AND price < 1200000 THEN CarLevel := 'Hatchback Model'; --Non compliant code (Dead stores should be removed) ELSIF price >= 1200000 AND price < 1500000 THEN CarLevel := 'Sedan Model'; --Non compliant code (Dead stores should be removed) ELSE CarLevel := 'Premium Model'; --Non compliant code (Dead stores should be removed) END IF; END;
Compliant Code Example
BEGIN
IF price > 0 AND price < 500000 THEN
CarLevel := 'Low Model';
ELSIF price >= 500000 AND price < 1200000 THEN
CarLevel := 'Hatchback Model';
ELSIF price >= 1200000 AND price < 1500000 THEN
CarLevel := 'Sedan Model';
ELSE
CarLevel := 'Premium Model';
END IF;
dbms_output.put_line('CarLevel:' || CarLevel); --Compliant code
END;