Search code examples
oracleattributesoracle10guser-defined-typesoracle-type

Get information about attrubute type in user defined object type


In oracle 11, i use column CHAR_USED in DBA_TYPE_ATTRS/ALL_TYPE_ATTRS/USER_TYPE_ATTRS.

select CHAR_USED from SYS.DBA_TYPE_ATTRS

But in 10 this column does not exist.

Test types:

create type TEST_TYPE_WITH_CHAR as object (
    A varchar2(10 char)
);

create type TEST_TYPE_WITH_BYTE as object (
    A varchar2(10 byte)
);

How to determine what type contains char, and which byte?


Solution

  • this info in 10g is there, but not exposed to us at all. so you have only a few options. (in 11g its only in the ALL view, not DBA/USER one unless they've added that in a recent patch)

    1. dba_source will have it , but thats a manual parsing of the sql to get that out.

    2. you can create a new view that joins to sys.attribute$ and extract decode(bitand(properties, 4096), 4096, 'C', 'B')

    3. you can amend the existing *type_attr views (though this wouldn't be supported by Oracle). just add decode(bitand(a.properties, 4096), 4096, 'C', 'B') in the view select parts (where "a" is the reference to sys.attribute$).

    an example of the new view..

    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>