So the advantage of using VARCHAR2 over VARCHAR is mainly that VARCHAR2 occupies variable size space in database depending on its length; this comes especially efficient when the column value inserted is null because virtually no space is occupied in this case. So by the same token, is there a data type for numbers that behaves in the same way so that when the number inserted is null no space is wasted in db?
因此,使用VARCHAR2而不是VARCHAR的优势主要在于VARCHAR2在数据库中占用可变大小的空间,具体取决于其长度;当插入的列值为null时,这尤其有效,因为在这种情况下几乎不占用空间。因此,出于同样的原因,数字的数据类型是否以相同的方式运行,以便当插入的数字为null时,db中没有浪费空间?
1 个解决方案
#1
4
Yes, variable-length number data type exists, it's called NUMBER.
是的,存在可变长度数字数据类型,它被称为NUMBER。
Oracle stores the precision (significant digits) and the scale separately, using the minimum space needed for precision (scale takes a single byte).
Oracle使用精度所需的最小空间(scale需要单个字节)分别存储精度(有效数字)和比例。
NUMBER(x,y) are a subtype of NUMBER, they are stored physically in the same way as regular NUMBER, they just have extra constraints.
NUMBER(x,y)是NUMBER的子类型,它们以与常规NUMBER相同的方式存储,它们只有额外的约束。
AFAIK, there is no equivalent of CHAR for numbers.
AFAIK,没有相应的CHAR数字。
You can see how Oracle stores data internally with the DUMP function:
您可以看到Oracle如何使用DUMP功能在内部存储数据:
SQL> select dump(1), dump(12345), dump(123456789) from dual;
DUMP(1) DUMP(12345) DUMP(123456789)
------------------ ------------------------ ------------------------------
Typ=2 Len=2: 193,2 Typ=2 Len=4: 195,2,24,46 Typ=2 Len=6: 197,2,24,46,68,90
As you can see the data length increases with precision.
如您所见,数据长度精确增加。
#1
4
Yes, variable-length number data type exists, it's called NUMBER.
是的,存在可变长度数字数据类型,它被称为NUMBER。
Oracle stores the precision (significant digits) and the scale separately, using the minimum space needed for precision (scale takes a single byte).
Oracle使用精度所需的最小空间(scale需要单个字节)分别存储精度(有效数字)和比例。
NUMBER(x,y) are a subtype of NUMBER, they are stored physically in the same way as regular NUMBER, they just have extra constraints.
NUMBER(x,y)是NUMBER的子类型,它们以与常规NUMBER相同的方式存储,它们只有额外的约束。
AFAIK, there is no equivalent of CHAR for numbers.
AFAIK,没有相应的CHAR数字。
You can see how Oracle stores data internally with the DUMP function:
您可以看到Oracle如何使用DUMP功能在内部存储数据:
SQL> select dump(1), dump(12345), dump(123456789) from dual;
DUMP(1) DUMP(12345) DUMP(123456789)
------------------ ------------------------ ------------------------------
Typ=2 Len=2: 193,2 Typ=2 Len=4: 195,2,24,46 Typ=2 Len=6: 197,2,24,46,68,90
As you can see the data length increases with precision.
如您所见,数据长度精确增加。