Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2543

"SIMPLE_INTEGER" should be used instead of "PLS_INTEGER"

    XMLWordPrintable

    Details

    • Message:
      Convert this variable to a "SIMPLE_INTEGER".
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Legacy Key:
      SimpleIntegerPlsIntegerCheck
    • Covered Languages:
      PL/SQL
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1h

      Description

      ORACLE 11g introduced the SIMPLE_INTEGER data type, which is a sub-type of PLS_INTEGER, and covers the same range. There are three main differences between the two types:

      • SIMPLE_INTEGER is always NOT NULL. So when the value of the declared variable is never going to be null, you can declare it as SIMPLE_INTEGER.
      • You will never face a numeric overflow using SIMPLE_INTEGER because this data type wraps around without giving any error.
      • The SIMPLE_INTEGER data type gives a major performance boost over PLS_INTEGER when the code is compiled in "NATIVE" mode, because arithmetic operations on SIMPLE_INTEGER type are performed directly at the hardware level.

      Noncompliant Code Example

      DECLARE
        v1 PLS_INTEGER; -- Noncompliant
        v2 VARCHAR2(10);
      BEGIN
        NULL;
      END;
      /
      

      Compliant Solution

      DECLARE
        v1 SIMPLE_INTEGER := 42;
        v2 VARCHAR2(10);
      BEGIN
        NULL;
      END;
      /
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: