在oracle 11中,我在DBA_TYPE_ATTRS
/ ALL_TYPE_ATTRS
/ USER_TYPE_ATTRS
中使用了列CHAR_USED。
select CHAR_USED from SYS.DBA_TYPE_ATTRS
但在本专栏10 does not exist中。
测试类型:
create type TEST_TYPE_WITH_CHAR as object (
A varchar2(10 char)
);
create type TEST_TYPE_WITH_BYTE as object (
A varchar2(10 byte)
);
如何确定哪个类型包含char,哪个字节?
答案 0 :(得分:1)
10g中的这些信息是存在的,但根本没有暴露给我们。所以你只有几个选择。 (在11g中它仅在ALL视图中,而不是DBA / USER,除非他们在最近的补丁中添加了它)
dba_source将拥有它,但这是一个手动解析sql来解决这个问题。
您可以创建一个连接到sys.attribute $的新视图并解压缩decode(bitand(properties, 4096), 4096, 'C', 'B')
您可以修改现有的* type_attr视图(尽管Oracle不支持此视图)。只需在视图选择部分中添加decode(bitand(a.properties, 4096), 4096, 'C', 'B')
(其中“a”是对sys.attribute $的引用)。
新视图的一个例子..
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> create view type_chars
2 as
3 select ta.owner, ta.type_name, ta.attr_name, decode(bitand(a.properties, 4096), 4096, 'C', 'B') char_used
4 from sys.attribute$ a, sys.type$ t, sys.obj$ o, dba_objects ob, dba_type_attrs ta
5 where ta.owner = ob.owner
6 and ta.type_name = ob.object_name
7 and a.toid = t.toid
8 and a.version# = t.version#
9 and t.toid = o.oid$
10 and o.subname is null
11 and ob.object_id = o.obj#
12 and a.name = ta.attr_name;
View created.
SQL> create type mytype as object (a varchar2(20), b number, c varchar2(30 char));
2 /
Type created.
SQL> select * from type_chars where type_name = 'MYTYPE' and owner= user;
OWNER TYPE_NAME ATTR_NAME C
------------------------------ ------------------------------ ------------------------------ -
DTD_TRADE MYTYPE A B
DTD_TRADE MYTYPE B B
DTD_TRADE MYTYPE C C
SQL>