oracle internal datatype

oracle内置数据类型有:

  • CHAR,VARCHAR2,NCHAR,NVARCHAR2
  • NUMBER
  • RAW
  • LONG,LONG RAW
  • DATE
  • TIMESTAMP
  • INTERVAL
  • CLOB,BLOB,NCLOB,BFILE
  • ROWID,UROWID

每列的数据类型并不存储在数据块中,而是存储在数据字典col$.type#。

下面总结一下常用的几种数据类型:

字符类型

  • char and varchar2(stroed in the database (single byte) character set)
  • char:字符长度上限为2000 characters,internal code=96
  • varchar2:字符长度上限为4000 characters,internal code=1
  • nchar and nvarchar2(stroed in a national (multi byte) character set)
  • nchar:字符长度上限为2000 characters,internal code=96
  • nvarchar2:字符长度上限为4000 characters,internal code=1

    Single-byte character sets can only encode 255 distinct characters at most. Several character sets have more than 255 characters, so need multiple bytes to represent them all. Unicode now encodes over 109000 characters across different scripts. http://en.wikipedia.org/wiki/Unicode http://download.oracle.com/docs/cd/E11882_01/server.112/e10729/ch6unicode.htm

字符类型按照acsii码进行转换,参考http://www.asciitable.com/

数值类型number

  • number类型存储在一个可变长的数组中
  • 存储格式为:length byte,sign bit/exponent,dight1,digit2,…,digit20
  • internal code=2
  • 首尾的0将被剥离
  • 0存储为0x80(128)

Both NUMBER and FLOAT data types share the same internal implementation. 20 digit bytes maximum + 1 exponent byte = 21 bytes. Yet numbers have a max length of 22. Why? It allows the length byte to be included with the number as an argument passed internally in code for backward compatibility with older code that hasn’t been touched. Internal API prefers numbers passed as two arguments (input_length, input_value)

 

number类型内部存储主要分为2部分:

  • first bit:sign/offset/exponent

  • digit bit(最多20 byte)

正数数值转换:
This number is positive because the first byte is greater than 128 (0x80).

  • Step 1 Exponent = first byte – (128 + 65 offset or 193)
  • Step 2 Subtract 1 from every other digit represented in decimal.
  • Step 3 Convert from base 100 to base 10.

  • Step 4 Add all the values.

负数数值转换:
This number is negative because the first byte is less than 128 (0x80).

  • Step 1 Exponent = 62 – first byte
  • Step 2 Subtract every other digit from 101.
  • Step 3 Convert from base 100 to base 10.

  • Step 4 Make sure to ignore the trailing byte if it is 0x66 (102).
  • Step 5 Add all the values.

If a negative number requires 21 bytes for its full representation, the trailing sort byte (0x66=102) is no longer required. Because the Oracle server does not represent any number using 22 bytes, the sorting conflict that forced the introduction of the trailing byte does not occur. In this case, all the bytes will be considered.

Hexidecimal to Number Conversion. (文档 ID 119698.1)

时间类型date:

  • date数据类型存储的信息有世纪、年、月、日、时、分、秒,不包括分秒以及time zone,internal code=12
  • date数据类型存储占用7字节
  • 前两个字节存储世纪和年(减100),接下来两个字节存储月和日,最后三个字节存储时分秒(减1)

 

此条目发表在Oracle分类目录,贴了标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注