pls_integer和binary_integer有什么区别?

Sat*_*hat 27 oracle plsql associative-array oracle10g

我继承了一些代码,这些代码将成为一些额外工作的基础.看看存储过程,我看到了很多关联数组.

其中一些由binary_integers索引,一些由pls_integers索引.这两者有什么不同吗?

我查看了文档,但除此之外:

PL/SQL数据类型PLS_INTEGERBINARY_INTEGER相同.为简单起见,本文档使用PLS_INTEGER来表示PLS_INTEGERBINARY_INTEGER.

我发现两者之间没有任何区别.那有什么区别?是否出于历史/兼容性原因?

我正在使用Oracle 10gR2

Thi*_*ilo 37

历史原因.他们过去在10g之前是不同的:

在8i和9i上,PLS_INTEGER明显快于BINARY_INTEGER.


在声明和操作整数时,Oracle提供了许多选项,包括:

INTEGER - 在STANDARD包中定义为NUMBER的子类型,此数据类型以完全独立于平台的方式实现,这意味着无论安装数据库的硬件如何,使用NUMBER或INTEGER变量执行的任何操作都应该相同.

BINARY_INTEGER - 在STANDARD包中定义为INTEGER的子类型.声明为BINARY_INTEGER的变量可以指定在-2 31 +1 .. 2 31 -1之间,也就是-2,147,483,647到2,147,483,647之间的值.在Oracle9i数据库第2版之前,BINARY_INTEGER是关联数组(也就是索引表)允许的唯一索引数据类型,如:

  TYPE my_array_t IS TABLE OF VARCHAR2(100) 
  INDEX BY BINARY_INTEGER
Run Code Online (Sandbox Code Playgroud)

PLS_INTEGER - 在STANDARD包中定义为BINARY_INTEGER的子类型.声明为PLS_INTEGER的变量可以指定在-2 31 +1 .. 2 31 -1之间,也就是-2,147,483,647到2,147,483,647之间的值.PLS_INTEGER操作使用机器算术,因此它们通常比NUMBER和INTEGER操作更快.此外,在Oracle数据库10g之前,它们比BINARY_INTEGER更快.但是,在Oracle数据库10g中,BINARY_INTEGER和PLS_INTEGER现在是相同的,可以互换使用.


小智 8

binary_integer并且pls_integer都是相同的.两者都是PL/SQL数据类型,范围为-2,147,648,467到2,147,648,467.

与执行相比integer并且binary_integer pls_integer非常快.因为pls_intger在机器算术binary_integer上操作和在库算术上操作.

pls_integer 来自oracle10g.

binary_integer 允许在oracle9i之前为关联数组索引整数.

清楚的例子:

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;
/ 
Run Code Online (Sandbox Code Playgroud)


Geb*_*lay 5

pls_integer和binary_integer之间的另一个区别是,当涉及pls_integer的计算溢出时,PL/SQL引擎将引发运行时异常.但是,即使存在溢出,涉及binary_integer的计算也不会引发异常.