在 Oracle 数据库中,支持的数据类型,可以从数据字典中直接得到。
例如,通过创建 col 视图的数据字典,可以清晰的获取类型列表。如下 SQL 中显示的 252 号 Boolean 布尔数据类型,是 Oracle Database 23c 中支持的,所以位列最后。
以下代码引用自 cdcore_str.sql 脚本:
create or replace view col
(tname, colno, cname, coltype, width, scale, precision, nulls, defaultval,
character_set_name) as
select t.name, c.col#, c.name,
decode(c.type#, 1, decode(c.charsetform, 2, 'NVARCHAR2', 'VARCHAR2'),
2, decode(c.scale, null,
decode(c.precision#, null, 'NUMBER', 'FLOAT'),
'NUMBER'),
8, 'LONG',
9, decode(c.charsetform, 2, 'NCHAR VARYING', 'VARCHAR'),
12, 'DATE',
23, 'RAW', 24, 'LONG RAW',
69, 'ROWID',
96, decode(c.charsetform, 2, 'NCHAR', 'CHAR'),
100, 'BINARY_FLOAT',
101, 'BINARY_DOUBLE',
105, 'MLSLABEL',
106, 'MLSLABEL',
111, 'REF '||'"'||ut.name||'"'||'.'||'"'||ot.name||'"',
112, decode(c.charsetform, 2, 'NCLOB', 'CLOB'),
113, 'BLOB', 114, 'BFILE', 115, 'CFILE',
121, '"'||ut.name||'"'||'.'||'"'||ot.name||'"',
122, '"'||ut.name||'"'||'.'||'"'||ot.name||'"',
123, '"'||ut.name||'"'||'.'||'"'||ot.name||'"',
178, 'TIME(' ||c.scale|| ')',
179, 'TIME(' ||c.scale|| ')' || ' WITH TIME ZONE',
180, 'TIMESTAMP(' ||c.scale|| ')',
181, 'TIMESTAMP(' ||c.scale|| ')'||' WITH TIME ZONE',
231, 'TIMESTAMP(' ||c.scale|| ')'||' WITH LOCAL TIME ZONE',
182, 'INTERVAL YEAR(' ||c.precision#||') TO MONTH',
183, 'INTERVAL DAY(' ||c.precision#||') TO SECOND(' ||
c.scale || ')',
208, 'UROWID',
252, 'BOOLEAN',
'UNDEFINED'),
c.length, c.scale, c.precision#,
decode(sign(c.null$),-1,'NOT NULL - DISABLED', 0, 'NULL',
'NOT NULL'), c.default$,
decode(c.charsetform, 1, 'CHAR_CS',
2, 'NCHAR_CS',
3, NLS_CHARSET_NAME(c.charsetid),
4, 'ARG:'||c.charsetid)
from sys.col$ c, sys."_CURRENT_EDITION_OBJ" t, sys.coltype$ ac,
sys.obj$ ot, sys."_BASE_USER" ut
where t.obj# = c.obj#
and t.type# in (2, 3, 4)
and t.owner# = userenv('SCHEMAID')
and bitand(c.property, 32) = 0 /* not hidden column */
and c.obj# = ac.obj#(+)
and c.intcol# = ac.intcol#(+)
and ac.toid = ot.oid$(+)
and ot.owner# = ut.user#(+)
/
官方文档中描述的数据类型和编码如下表所示:
| Code | Data Type | Description |
|---|---|---|
1 |
| Variable-length character string having maximum length
Refer to Extended Data Types for more information on the
|
1 |
| Variable-length Unicode character string having maximum length
Refer to Extended Data Types for more information on the |
2 |
| Number having precision |
2 |
| A subtype of the |
8 |
| Character data of variable length up to 2 gigabytes, or 231 -1 bytes. Provided for backward compatibility. |
12 |
| Valid date range from January 1, 4712 BC, to December 31, 9999 AD. The default format is determined explicitly by the |
100 |
| 32-bit floating point number. This data type requires 4 bytes. |
101 |
| 64-bit floating point number. This data type requires 8 bytes. |
180 |
| Year, month, and day values of date, as well as hour, minute, and second values of time, where |
181 |
| All values of |
231 |
| All values of
The default format is determined explicitly by the |
182 |
| Stores a period of time in years and months, where |
183 |
| Stores a period of time in days, hours, minutes, and seconds, where
The size is fixed at 11 bytes. |
23 |
| Raw binary data of length
Refer to Extended Data Types for more information on the |
24 |
| Raw binary data of variable length up to 2 gigabytes. |
69 |
| Base 64 string representing the unique address of a row in its table. This data type is primarily for values returned by the |
208 |
| Base 64 string representing the logical address of a row of an index-organized table. The optional |
96 |
| Fixed-length character data of length
|
96 |
| Fixed-length character data of length |
112 |
| A character large object containing single-byte or multibyte characters. Both fixed-width and variable-width character sets are supported, both using the database character set. Maximum size is (4 gigabytes - 1) * (database block size). |
112 |
| A character large object containing Unicode characters. Both fixed-width and variable-width character sets are supported, both using the database national character set. Maximum size is (4 gigabytes - 1) * (database block size). Stores national character set data. |
113 |
| A binary large object. Maximum size is (4 gigabytes - 1) * (database block size). |
114 |
| Contains a locator to a large binary file stored outside the database. Enables byte stream I/O access to external LOBs residing on the database server. Maximum size is 4 gigabytes. |
119 |
| Maximum size is 32 megabytes. |
参考文献




