G-2220
🆓Warning
Try to use PLS_INTEGER instead of NUMBER for arithmetic operations with integer values.
Reason
pls_integer having a length of -2,147,483,648 to 2,147,483,647, on a 32bit system.
There are many reasons to use pls_integer instead of number:
pls_integeruses less memorypls_integeruses machine arithmetic, which is up to three times faster than library arithmetic, which is used bynumber.
Example
Non-Compliant Example
declare
l_result number(9,0);
co_upper_bound constant pls_integer := 1e8;
begin
l_result := 0;
<<burning_cpu>>
for i in 1..co_upper_bound
loop
if i > 0 then
l_result := l_result + 1;
end if;
end loop burning_cpu;
sys.dbms_output.put_line(l_result);
end;
/Issues
| Line | Column | Message |
|---|---|---|
| 2 | 19 |
Compliant Solution - ★★★★★
declare
l_result pls_integer;
co_upper_bound constant pls_integer := 1e8;
begin
<<burning_less_cpu>>
for i in 1..co_upper_bound
loop
if i > 0 then
l_result := l_result + 1;
end if;
end loop burning_less_cpu;
sys.dbms_output.put_line(l_result);
end;
/Parameters
Use parameters to customize the rule to your needs.
| Parameter | Description | Default Value |
|---|---|---|
| DisableAllQuickFix | Comma-separated list of rules for which a quick fix should not be applied to all the problems in a file. | Core G-3130 |
References
- same as plsql:S4081
- same as Trivadis G-2220