十进制(s,p)或数字(s,p)? [英] decimal(s,p) or number(s,p)?

查看:374
本文介绍了十进制(s,p)或数字(s,p)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



然而,对我来说的问题仍然是 -


  1. 这个数据是如何处理的?

  2. 是否需要使用ANSI类型而不是Oracle的内置类型?

  3. 如果目标类型在数据迁移期间会有影响是Oracle内置类型?


解决方案

在Oracle中,他们是一样的


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


下面的表格显示了 DECIMAL(p,s )内部处理为 NUMBER(p,s)

  SQL>创建表t(小数(*,5),b数字(*,5)); 

创建表

SQL>描述
名称类型Nullable默认评论
---- ----------- -------- ------- ------- -
A NUMBER(*,5)Y
B NUMBER(*,5)Y

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

  SQL>创建表t(十进制,b数字,十进制(5),十进制(5)); 

创建表

SQL>描述
名称类型Nullable默认评论
---- --------- -------- ------- --------
A INTEGER Y
B NUMBER Y
C NUMBER(5)Y
D NUMBER(5)Y


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.

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 ?

解决方案

In Oracle, they are the same:

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.

The table below this quote shows that DECIMAL(p,s) is treated internally as a 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:

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   

这篇关于十进制(s,p)或数字(s,p)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆