oracle 小数(s,p)还是数字(s,p)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11031409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:16:00  来源:igfitidea点击:

decimal(s,p) or number(s,p)?

oracledb2ansitype-conversion

提问by Raghav

recently, while working on a db2 -> oracle migration project, we came across this situation. the developers were inadvertently creating new table structures using decimal(s,p) columns. I didn't remember Oracle supporting this, but then some digging showed that its a ANSI data type therefore supported by oracle.

最近,在做 db2 -> oracle 迁移项目时,我们遇到了这种情况。开发人员无意中使用小数(s,p)列创建了新的表结构。我不记得 Oracle 支持这一点,但后来一些挖掘表明它是 oracle 支持的 ANSI 数据类型。

However, question for me remained -

然而,对我来说问题仍然存在——

  1. how is this data handled internally ?
  2. is there a cost of using ANSI types instead of Oracle's built in types ?
  3. Will there be an impact during the data migration if the target type was Oracle built-in type ?
  1. 这些数据是如何在内部处理的?
  2. 使用 ANSI 类型而不是 Oracle 的内置类型是否有成本?
  3. 如果目标类型是Oracle内置类型,在数据迁移过程中会不会有影响?

采纳答案by Vincent Malgrat

In Oracle, they are the same:

在 Oracle 中,它们是相同的

SQL statements that create tables and clusters can also use ANSI data types and data types from the IBM products SQL/DS and DB2. Oracle recognizes the ANSI or IBM data type name that differs from the Oracle Database data type name. It converts the data type to the equivalent Oracle data type, records the Oracle data type as the name of the column data type, and stores the column data in the Oracle data type based on the conversions shown in the tables that follow.

创建表和集群的 SQL 语句也可以使用来自 IBM 产品 SQL/DS 和 DB2 的 ANSI 数据类型和数据类型。Oracle 识别与 Oracle 数据库数据类型名称不同的 ANSI 或 IBM 数据类型名称。它将数据类型转换为等效的 Oracle 数据类型,将 Oracle 数据类型记录为列数据类型的名称,并根据下表中显示的转换将列数据存储在 Oracle 数据类型中。

The table below this quote shows that DECIMAL(p,s)is treated internally as a NUMBER(p,s):

此引用下方的表格显示在DECIMAL(p,s)内部被视为NUMBER(p,s)

SQL> create table t (a decimal(*,5), b number (*, 5));

Table created

SQL> desc t;
Name Type        Nullable Default Comments 
---- ----------- -------- ------- -------- 
A    NUMBER(*,5) Y                         
B    NUMBER(*,5) Y  

However, the scale defaults to 0 for DECIMAL, which means that DECIMAL(*)is treated as NUMBER(*, 0), i.e. INTEGER:

但是,对于 ,比例默认为 0 DECIMAL,这意味着将DECIMAL(*)其视为NUMBER(*, 0),即INTEGER

SQL> create table t (a decimal, b number, c decimal (5), d decimal (5));

Table created

SQL> desc t;
Name Type      Nullable Default Comments 
---- --------- -------- ------- -------- 
A    INTEGER   Y                         
B    NUMBER    Y                         
C    NUMBER(5) Y                         
D    NUMBER(5) Y   

回答by JasonMing

Actually, there is difference between decimal and number. Decimal will truncate the value which is over-scale, number will round the value.

实际上,小数和数字之间是有区别的。Decimal 将截断超出比例的值,number 将舍入该值。