G-1040: Avoid dead code.
Reason
Any part of your code, which is no longer used or cannot be reached, should be eliminated from your programs to simplify the code.
Example (bad)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 | declare
co_dept_purchasing constant departments.department_id%type := 30;
begin
if 2 = 3 then -- dead code detection works with literals only
null; -- some dead code here
end if;
null; -- some enabled code here
<<my_loop>>
loop
exit my_loop when true;
null; -- some dead code here
end loop my_loop;
null; -- some other enabled code here
case
when 1 = 1 and 'x' = 'y' then -- dead code detection works with literals only
null; -- some dead code here
else
null; -- some further enabled code here
end case;
<<my_loop2>>
for r_emp in (
select last_name
from employees
where department_id = co_dept_purchasing
or commission_pct is not null
and 5 = 6 -- dead code detection works with literals only
)
-- "or commission_pct is not null" is dead code
loop
sys.dbms_output.put_line(r_emp.last_name);
end loop my_loop2;
return;
null; -- some dead code here
end;
/
|
Example (good)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 | declare
co_dept_admin constant dept.deptno%type := 10;
begin
null; -- some enabled code here
null; -- some other enabled code here
null; -- some further enabled code here
<<my_loop2>>
for r_emp in (
select last_name
from employees
where department_id = co_dept_admin
or commission_pct is not null
)
loop
sys.dbms_output.put_line(r_emp.last_name);
end loop my_loop2;
end;
/
|