1. 功能
dump 函数返回一个包含数据类型代码,所占字节长度以及内部存储编码的字符串
2. 参数
dump(expr[,return_fmt[,start_position][,length]])
- expr :表达式
- return_fmt : 指定返回值的格式,可以有以下选项:
- 8 :返回以8进制的结果值
- 10 :返回以10进制的结果值 【默认值】
- 16 :返回以16进制的结果值
- 17 :返回以每个字符并以指定字符分隔的结果值
默认情况下,返回值不包含字符集的信息。如果想要获取 expr 对应的字符集, 需要设置 return_fmt 的值为以上的取值的基础上再加上 1000。例如设置 return_fmt 为 1008 就代表了返回8进制的结果值以及对应的字符集。
- start_position :返回开始的位置
- length :返回的长度
此外,dump函数并不直接支持 clob 数据类型,但是可以通过数据转换支持 clob。
3.返回值
类型 存储的字节长度: 符号/指数位/ascii,数字位1,数字位2,数字位3,数字位4…
例如:Typ=2 Len=2: 192,2
- 数据类型 type 代表 oracle 数据类型的内部代号,对应的数据库的数据类型如下:
1 varhcar2/nvarchar2 2 number/float 8 long 12 date 23 raw 24 long raw 69 rawid 96 char/nchar 100 binary_float 101 binary_double 112 clob/nclob 113 blob 114 bfile 180 timestamp 181 timestamp with time zone 182 interval year to month 183 interval day to second 208 urowid 231 timestamp with local time zone
- 符号/指数位/ascii
1. 如果 expr 的数据类型为 number
- 如果 expr 是正数
expr = (数字位1 + 1) * 100 ^ (符号/指数位 – 195 - 0) + (数字位2 + 1) * 100 ^ (符号/指数位 – 195 - 1)+ (数字位3 + 1) * 100 ^ (符号/指数位 – 195 - 3)+ …
- 如果 expr 是负数
expr = (101 - 数字位1) * 100 ^ (62 - 符号/指数位 - 0)+ (101 - 数字位1) * 100 ^ (62 - 符号/指数位 - 1)+ (101 - 数字位3) * 100 ^ (62 - 符号/指数位 - 2)+ …
其中,如果 expr 的长度(len) 小于 21,dump 的时候会自动加上 102(方便排序)
2. 如果 expr 的数据类型为 char 或 varchar2
expr = ascii 码
4. 例子
SQL> select dump(100,8) from dual;
DUMP(100,8)
------------------
Typ=2 Len=2: 302,2
SQL> select dump(100,10) from dual;
DUMP(100,10)
------------------
Typ=2 Len=2: 194,2
SQL> select dump(100) from dual;
DUMP(100)
------------------
Typ=2 Len=2: 194,2
SQL> select dump(100,16) from dual;
DUMP(100,16)
-----------------
Typ=2 Len=2: c2,2
typ=2 len=2 代表是number数据类型,占用2个字节
SQL> select dump(234.56, 10) from dual;
DUMP(234.56,10)
------------------------
Typ=2 Len=4: 194,3,35,57
指数位 = 195 – 194 = 1
数字位1 : 3 => (3 – 1) * 100 ^ ( 指数位 – 0) = 200
数字位2: :35 => (35 – 1) * 100 ^ (指数位 - 1) = 34
数字位3 :57 => (57 – 1) * 100 ^ (指数位 - 2) = 0.56
数字位1 + 数字位2 + 数字位3 = 234.56
SQL> select dump(-234.56, 10) from dual;
DUMP(-234.56,10)
----------------------------
Typ=2 Len=5: 61,99,67,45,102
指数位 = 62 – 61 = 1
数字位1 :99 => (101 – 99) * 100 ^ (指数位 – 0) = 200
数字位2 :67 => (101 – 67) * 100 ^ (指数位 – 1) = 34
数字位3 :45 => (101 – 45) * 100 ^ (指数位 – 2) = 0.56
SQL> select dump(-2342342342341234213414123423423.2) from dual;
DUMP(-2342342342341234213414123423423.2)
-----------------------------------------------------------------------
Typ=2 Len=19: 47,99,67,78,59,67,78,60,78,59,88,60,60,78,59,67,78,81,102
SQL> select dump(-23421412341234123412342314234234123412.2) from dual;
DUMP(-23421412341234123412342314234234123412.2)
----------------------------------------------------------------------------
Typ=2 Len=21: 44,78,59,87,89,67,89,67,89,67,89,67,78,87,78,59,67,89,67,89,81
如果 expr 的长度小于21,会在最后加上 102
SQL> select dump('abc', 10) from dual;
DUMP('ABC',10)
----------------------
Typ=96 Len=3: 97,98,99
SQL> select chr(97), chr(98), chr(99) from dual;
C C C
- - -
a b c
typ=96 len=3 说明是 char 数据类型,占用 3 个字节,后面就代表对应字符的 ascii 码
SQL> select dump(12345.67, 10) from dual;
DUMP(12345.67,10)
------------------------------------------------
Typ=2 Len=5: 195,2,24,46,68
SQL> select dump(12345.67, 10, 2,3) from dual;
DUMP(12345.67,10,2,3
---------------------------------------------
Typ=2 Len=5: 2,24,46
SQL> select dump(12345.67, 10, 2) from dual;
DUMP(12345.67,10,2)
----------------------------------------------
Typ=2 Len=5: 2,24,46,68
SQL> select dump(12345.67, 16, 2, 3) from dual;
DUMP(12345.67,16,2,3
------------------------------------------
Typ=2 Len=5: 2,18,2e
start_position 和 length 参数一起决定返回存储编码的字符串
参考:
http://www.eygle.com/archives/2005/12/how_oracle_stor.html
oracle 11g dump 参考文档(http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions055.htm#SQLRF00635)