转;

pls_integer类型

2011-08-22 16:49:06 heqiyu34 阅读数 13413更多

分类专栏: Oracle
 

今天在看一个触发器代码的时候碰到了一个pls_integer类型,以前没碰到过,记录一下:

PLS_INTEGER可以存储一个有符号的整形值,其精度范围和BINARY_INTEGER一样,是:-2^31~2^31。

PLS_INTEGER和NUMBER比较起来,其优点是:
1).占有较少的存储空间;
2).可以直接进行算术运算(在NUMBER上不能直接进行算术运算,如果要计算,NUMBER必须先被转换成二进制)。所以在进行算术的时候PLS_INTEGER比NUMBER和BINARY_INTEGER快一些。

PLS_INTEGER和BINARY_INTEGER区别:
PLS_INTEGER进行的运算发生溢出的时候,会触发异常。但是当BINARY_INTEGER运算发生溢出时,如果可以指派给一个NUMBER变量(没有超出NUMBER的精度范围)的话就不会触发异常。

Benefits of Using
PLS_INTEGER
Datatype in PL/SQL
If you have a whole-number counter, for example in a loop or record counter, consider using a datatype ofPLS_INTEGER instead of INTEGER or NUMBER. When declaring an integer variable,PLS_INTEGER
is the most efficient numeric datatype because its values require less
storage than INTEGER or NUMBER values, which are represented internally
as 22-byte Oracle numbers. Also,PLS_INTEGER operations
use machine arithmetic, so they are faster than BINARY_INTEGER, INTEGER, or NUMBER operations, which use library arithmetic.
--------------------------------------------------------------------------
PLS_INTEGER Datatype
You use the PLS_INTEGER datatype to store signed integers. Its magnitude
range is -2147483648 to 2147483647, represented in 32 bits. PLS_INTEGER
values require less storage than NUMBER values and NUMBER subtypes.
Also, PLS_INTEGER operations use hardware arithmetic,
so they are faster than NUMBER operations, which use library
arithmetic. For efficiency, use PLS_INTEGER for all calculations that
fall within its magnitude range. For calculations outside the range of
PLS_INTEGER, you can use the INTEGER datatype.

Note:

The BINARY_INTEGER and PLS_INTEGER datatypes are identical. See "Change to the BINARY_INTEGER Datatype".

When a calculation with two PLS_INTEGER datatypes overflows the
magnitude range of PLS_INTEGER, an overflow exception is raised even if
the result is assigned to a NUMBER datatype.

tips:1)pls_integer类型也是数字类型,但和number类型不同,number可以存储实数,而pls_integer只能存储-2147483647到+2147483647之间的整数,如果使用pls_integer类型时发生溢出,系统将会报错。
 
  
   2)binary_integer与pls_integer类似,在9.2版本以前大量使用,从9.2以后,从Oracle内部一些组件可以看的出,大有被pls_integer取代之势(pls_integer比binary_integer具有更少的存储开销和更好的访问性能,所以Oracle从9.2以后推荐你尽量能使用pls_integer就使用pls_integer)。它也是只能存储-2147483647到+2147483647之间的整数。
 
      3)在oracle
11g中,又增加了一个新的类似的数据类型simple_integer,不过simple_integer不能包含空值,它的取值范围是[-2147483648..2147483647]。在11g中,simple_integer相对pls_integer在性能上又有所提高,如果在实际的pl/sql中既不需要overflow检查也不会包含null值,Oracle建议你使用simple_integer.
 

来源:http://www.itpub.net/thread-1106923-1-1.html

注:Binary_Integer
与 Pls_Integer 都是整型类型.
Binary_Integer类型变量值计算是由Oracle来执行,不会出现溢出,但是执行速度较慢,因为它是由Oracle模拟执行。而Pls_Integer的执行是由硬件即直接由CPU来运算,因而会出现溢出,但其执行速度较前者快许多。

最新文章

  1. sqlserver附加 mdf、ldf的方法(手记)
  2. Testing - 测试基础 - 探索
  3. 大数据——Hadoop集群坏境CentOS安装
  4. Apache配置简单http认证
  5. MySQL瘦身
  6. php测试程序运行时间和占用内存情况
  7. Validform使用
  8. MSSQL导入数据时,出现“无法截断表 因为表正由Foreign key引用”错误
  9. MapReduce中的作业调度
  10. Android学习笔记:ListView简单应用--显示文字列表
  11. Linux目录结构和常用命令
  12. Zookeeper的安装和初步使用
  13. ctf中常见注入题源码及脚本分析
  14. 201521123003《Java程序设计》第10周学习笔记
  15. linux目录的特点
  16. SQL游标在递归是的时候提示 "游标" 名称已经存在的问题
  17. Ubuntu 14 如何解压 .zip、.rar 文件
  18. argparse - 命令行选项与参数解析
  19. PHP中MySQL、MySQLi和PDO的用法和区别
  20. scrapy 自定义图片路径保存,并存到数据库中

热门文章

  1. SVM: 相对于logistic regression而言SVM的 cost function与hypothesis
  2. service worker(二)之主页面与service worker通信
  3. Backpack IV
  4. SPA项目开发--左侧树加首页导航
  5. 六.搭建基本的Web服务
  6. 生活 RH阴性血 AB型
  7. BZOJ3551 Peaks加强版 [Kruskal重构树,主席树]
  8. JSP简单标签的开发
  9. std_msgs/String.msg
  10. SpringBoot整合ElasticSearch:基于SpringDataElasticSearch