Home
SIMPLE_INTEGER should be used instead of PLS_INTEGER
Description
The rule "SIMPLE_INTEGER should be used instead of PLS_INTEGER" states that the SIMPLE_INTEGER data type should be used instead of the PLS_INTEGER data type when declaring variables in PL/SQL code. SIMPLE_INTEGER is a 32-bit signed integer data type, while PLS_INTEGER is a 64-bit signed integer data type. Using SIMPLE_INTEGER instead of PLS_INTEGER will result in more efficient code, as SIMPLE_INTEGER is a smaller data type and requires less memory. Additionally, SIMPLE_INTEGER is more portable, as it is supported by all Oracle databases.
Key Benefits
- Performance: SIMPLE_INTEGER is faster than PLS_INTEGER as it is not subject to the same overhead of PL/SQL.
- Portability: SIMPLE_INTEGER is portable across different platforms, whereas PLS_INTEGER is not.
- Ease of Use: SIMPLE_INTEGER is easier to use than PLS_INTEGER as it is simpler to understand and requires fewer lines of code.
Non-compliant Code Example
DECLARE
num VARCHAR2(50);
counter PLS_INTEGER := 81; --Non compliant code (PLS_INTEGER is used instead of SIMPLE_INTEGER)
BEGIN
FOR i in 2..ROUND(SQRT(counter))
LOOP
IF counter MOD i = 0 THEN
num := ' is not a prime number';
GOTO print_now;
END IF;
END LOOP;
num := ' is a prime number';
<<print_now>>
DBMS_OUTPUT.PUT_LINE(TO_CHAR(counter) || num);
END;
Compliant Code Example
DECLARE
num VARCHAR2(50);
counter INTEGER := 81; --Compliant code (SIMPLE_INTEGER is used instead of PLS_INTEGER)
BEGIN
FOR i in 2..ROUND(SQRT(counter))
LOOP
IF counter MOD i = 0 THEN
num := ' is not a prime number';
GOTO print_now;
END IF;
END LOOP;
num := ' is a prime number';
<<print_now>>
DBMS_OUTPUT.PUT_LINE(TO_CHAR(counter) || num);
END;