What's the difference between pls_integer and binary_integer?

后端 未结 3 1870
盖世英雄少女心
盖世英雄少女心 2020-12-08 20:03

I\'ve inherited some code which is going to be the base for some additional work. Looking at the stored procs, I see quite a lot of associative-arrays.

Some of these

相关标签:
3条回答
  • 2020-12-08 20:40

    Historical reasons. They used to be different before 10g:

    On 8i and 9i, PLS_INTEGER was noticeably faster than BINARY_INTEGER.


    When it comes to declaring and manipulating integers, Oracle offers lots of options, including:

    INTEGER - defined in the STANDARD package as a subtype of NUMBER, this datatype is implemented in a completely platform-independent fashion, which means that anything you do with NUMBER or INTEGER variables should work the same regardless of the hardware on which the database is installed.

    BINARY_INTEGER - defined in the STANDARD package as a subtype of INTEGER. Variables declared as BINARY_INTEGER can be assigned values between -231+1 .. 231-1, aka -2,147,483,647 to 2,147,483,647. Prior to Oracle9i Database Release 2, BINARY_INTEGER was the only indexing datatype allowed for associative arrays (aka, index-by tables), as in:

      TYPE my_array_t IS TABLE OF VARCHAR2(100) 
      INDEX BY BINARY_INTEGER
    

    PLS_INTEGER - defined in the STANDARD package as a subtype of BINARY_INTEGER. Variables declared as PLS_INTEGER can be assigned values between -231+1 .. 231-1, aka -2,147,483,647 to 2,147,483,647. PLS_INTEGER operations use machine arithmetic, so they are generally faster than NUMBER and INTEGER operations. Also, prior to Oracle Database 10g, they are faster than BINARY_INTEGER. In Oracle Database 10g, however, BINARY_INTEGER and PLS_INTEGER are now identical and can be used interchangeably.

    0 讨论(0)
  • 2020-12-08 20:43

    Another difference between pls_integer and binary_integer is that when calculations involving a pls_integer overflow the PL/SQL engine will raise a run time exception. But, calculations involving a binary_integer will not raise an exception even if there is an overflow.

    0 讨论(0)
  • 2020-12-08 20:53

    binary_integer and pls_integer both are same. Both are PL/SQL datatypes with range -2,147,648,467 to 2,147,648,467.

    Compared to integer and binary_integer pls_integer very fast in excution. Because pls_intger operates on machine arithmetic and binary_integer operes on library arithmetic.

    pls_integer comes from oracle10g.

    binary_integer allows indexing integer for assocative arrays prior to oracle9i.

    Clear example:

    SET TIMING ON
    
    declare
      num   integer := 0;
      incr  integer := 1;
      limit integer := 100000000;
    begin
      while num < limit loop
        num := num + incr;
      end loop;
    end;
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:20.23
    ex:2
    declare
      num   binary_integer := 0;
      incr  binary_integer := 1;
      limit binary_integer := 100000000;
    begin
      while num < limit loop
        num := num + incr;
      end loop;
    end;
    / 
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:05.81
    ex:3
    declare
      num   pls_integer := 0;
      incr  pls_integer := 1;
      limit pls_integer := 100000000;
    begin
      while num < limit loop
        num := num + incr;
      end loop;
    end;
    / 
    
    0 讨论(0)
提交回复
热议问题