zoukankan      html  css  js  c++  java
  • PL/SQL Datatypes

    Overview of Predefined PL/SQL Datatypes

    A scalar type has no internal components. It holds a single value, such as a number or
    character string.

    A composite type has internal components that can be manipulated individually, such
    as the elements of an array.

    A reference type holds values, called pointers, that designate other program items.

    A LOB type holds values, called lob locators, that specify the location of large objects,
    such as text blocks or graphic images, that are stored separately from other database
    data.
    Figure 3–1 shows the predefined PL/SQL datatypes. The scalar types fall into four
    families, which store number, character, Boolean, and date/time data, respectively.

    BINARY_INTEGER(PLS_INTEGER)
    You use the BINARY_INTEGER datatype to store signed integers. Its magnitude range
    is -2**31 .. 2**31.
    BINARY_INTEGER values require less storage than NUMBER values. Arithmetic
    operations on BINARY_INTEGER values are also faster than NUMBER arithmetic.
    BINARY_INTEGER and PLS_INTEGER both have these advantages. Because PLS_
    INTEGER was faster in earlier releases, you might use it instead of BINARY_INTEGER
    in code that will run on older databases.

    PLS_INTEGER
    You use the PLS_INTEGER datatype to store signed integers. Its magnitude range is
    -2**31 .. 2**31. PLS_INTEGER values require less storage than NUMBER values. Also,
    PLS_INTEGER operations use machine arithmetic, so they are faster than NUMBER and
    BINARY_INTEGER operations, which use library arithmetic. For efficiency, use PLS_
    INTEGER for all calculations that fall within its magnitude range.
    Although PLS_INTEGER and BINARY_INTEGER have the same magnitude range,
    they are not fully compatible. When a PLS_INTEGER calculation overflows, an
    exception is raised. However, when a BINARY_INTEGER calculation overflows, no
    exception is raised if the result is assigned to a NUMBER variable.
    Because of this small semantic difference, you might want to continue using BINARY_
    INTEGER in old applications for compatibility. In new applications, always use PLS_
    INTEGER for better performance.

    结论:在版本低的库中使用BINARY_INTEGER,在版本高的库中,推荐使用PLS_INTEGER

    NUMBER(我们最常用的NUMBER)

    You use the NUMBER datatype to store fixed-point or floating-point numbers. Its
    magnitude range is 1E-130 .. 10E125. If the value of an expression falls outside this
    range, you get a numeric overflow or underflow error. You can specify precision, which is
    the total number of digits, and scale, which is the number of digits to the right of the
    decimal point. The syntax follows:
    NUMBER[(precision,scale)]
    To declare fixed-point numbers, for which you must specify scale, use the following
    form:
    NUMBER(precision,scale)
    To declare floating-point numbers, for which you cannot specify precision or scale
    because the decimal point can "float" to any position, use the following form:
    NUMBER
    To declare integers, which have no decimal point, use this form:
    NUMBER(precision) -- same as NUMBER(precision,0)
    You cannot use constants or variables to specify precision and scale; you must use
    integer literals. The maximum precision of a NUMBER value is 38 decimal digits. If you
    do not specify precision, it defaults to 38 or the maximum supported by your system,
    whichever is less.
    Scale, which can range from -84 to 127, determines where rounding occurs. For
    instance, a scale of 2 rounds to the nearest hundredth (3.456 becomes 3.46). A negative
    scale rounds to the left of the decimal point. For example, a scale of -3 rounds to the
    nearest thousand (3456 becomes 3000). A scale of 0 rounds to the nearest whole
    number. If you do not specify scale, it defaults to 0.

     

  • 相关阅读:
    C++ 引用与常量
    树的三种存储方法
    二叉树 基本运算
    Win10阻止电脑关机时弹出正在关闭应用的方法及恢复
    使用spring+quartz配置多个定时任务(包括项目启动先执行一次,之后再间隔时间执行)
    MySQL为某数据库中所有的表添加相同的字段
    Mysql定时任务详情
    MYSQL存储过程即常用逻辑
    后台发送请求,HttpClient的post,get各种请求,带header的请求
    java后台发送请求获取数据,并解析json数据
  • 原文地址:https://www.cnblogs.com/caroline/p/2406870.html
Copyright © 2011-2022 走看看