Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Oracle pls_integer tips

Oracle Database Tips by Donald BurlesonApril 1, 2015

Question:  What is the pls_integer, and how do I use pls_integer in PL/SQL.

Answer:  For integer values, the PLS_INTEGER type gives better performance and requires less storage space than either INTEGER or NUMBER types.  The PLS_INTEGER type uses machine arithmetic, while NUMBER and its subtypes are represented in a special internal format which requires additional calls to library routines during operations.  In addition, constrained types like INTEGER require extra runtime checks making them even less efficient.

Also see PLS Integer versus Number.  It is a good practice to use PLS_INTEGER versus NUMBER. The PLS_INTEGER data Type was introduced in PL/SQL version 2.2 and has a  range of  -2147483647 to 2147483647.

Use of the PLS_INTEGER data type in PL/SQL involves less internal instructions to process, thus increasing performance. The PLS_INTEGER is useful for counters and integer operations

An example use of the PLS_INTEGER would be:

DECLARE
   lv_temp_cond_num    PLS_INTEGER := 10;
BEGIN
   IF lv_temp_cond_num = 1 THEN

The BINARY_INTEGER and PLS_INTEGER types give similar performance in Oracle 10g, but PLS_INTEGER is the preferred type when using Oracle 8i and 9i.

The integer_test.sql script compares the performance of the NUMBER, INTEGER, PLS_INTEGER and BINARY_INTEGER types.

integer_test.sql

SET SERVEROUTPUT ON
DECLARE
  l_number1          NUMBER := 1;
  l_number2          NUMBER := 1;
  l_integer1         INTEGER := 1;
  l_integer2         INTEGER := 1;
  l_pls_integer1     PLS_INTEGER := 1;
  l_pls_integer2     PLS_INTEGER := 1;
  l_binary_integer1  BINARY_INTEGER := 1;
  l_binary_integer2  BINARY_INTEGER := 1;
  l_loops            NUMBER := 10000000;
  l_start            NUMBER;
BEGIN
  -- Time NUMBER.
  l_start := DBMS_UTILITY.get_time;
 

  FOR i IN 1 .. l_loops LOOP
    l_number1 := l_number1 + l_number2;
  END LOOP;
  DBMS_OUTPUT.put_line('NUMBER         : ' ||
                       (DBMS_UTILITY.get_time - l_start));

  -- Time INTEGER.
  l_start := DBMS_UTILITY.get_time; 

  FOR i IN 1 .. l_loops LOOP
    l_integer1 := l_integer1 + l_integer2;
  END LOOP;

  DBMS_OUTPUT.put_line('INTEGER        : ' ||
                       (DBMS_UTILITY.get_time - l_start));

  -- Time PLS_INTEGER.
  l_start := DBMS_UTILITY.get_time; 

  FOR i IN 1 .. l_loops LOOP
    l_pls_integer1 := l_pls_integer1 + l_pls_integer2;
  END LOOP; 

  DBMS_OUTPUT.put_line('PLS_INTEGER    : ' ||
                       (DBMS_UTILITY.get_time - l_start));

  -- Time BINARY_INTEGER.
  l_start := DBMS_UTILITY.get_time; 

  FOR i IN 1 .. l_loops LOOP
    l_binary_integer1 := l_binary_integer1 + l_binary_integer2;
  END LOOP; 

  DBMS_OUTPUT.put_line('BINARY_INTEGER : ' ||
                       (DBMS_UTILITY.get_time - l_start));
END;
/

The results of the script run against different versions of Oracle are listed below.  Ignore the comparison between versions as each is on a different server.  Instead concentrate on the relative performance within a single version.

SQL> -- Oracle 8i
SQL> @integer_test.sql
NUMBER         : 3037
INTEGER        : 5002
PLS_INTEGER    : 2664
BINARY_INTEGER : 8511

PL/SQL procedure successfully completed.

SQL>

SQL> -- Oracle 9i
SQL> @integer_test.sql
NUMBER         : 652
INTEGER        : 1006
PLS_INTEGER    : 511
BINARY_INTEGER : 1285

PL/SQL procedure successfully completed.

SQL>

SQL> -- Oracle 10g
SQL> @integer_test.sql
NUMBER         : 191
INTEGER        : 376
PLS_INTEGER    : 88
BINARY_INTEGER : 93

PL/SQL procedure successfully completed.

From these results, it is clear that PLS_INTEGER types are the most efficient types to use in all versions of Oracle.  It can also be said that NUMBER types are always more efficient than INTEGER types.  In Oracle 10g, the BINARY_INTEGER type is almost as efficient and the PLS_INTEGER type, but in previous versions it is the worst performing type.


 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.


 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster