The Dictionary in the Data Dictionary

Today’s journey takes on

a trip into Oracle’s data dictionary, specifically, the dictionary

part or aspect of it. It’s interesting and informative to take a

peak under the covers and see how Oracle, (the product, that is),

is put together. Aside from trying to reverse engineer things,

looking at the underlying components presents an “If Oracle did it

this way, maybe I can too” learning paradigm. For example,

normalization is a huge part of database design, so it’s fair to

ask (or look, in this case) how well the SYS tables are normalized.

Much, and practically all for that matter, of what you query from

or against in the data dictionary is based on views, and as we all

know, views are usually based on tables. What is in those tables

and how does it all fit together?

DICTIONARY and

DICT

The DICTIONARY view contains metadata about other data

dictionary items. Most people familiar with Oracle’s data

dictionary will say that the data dictionary is based entirely on

views on tables owned by SYS. Well, yes, but to be more precise

(using the DICTIONARY “view” in this case), that’s not entirely

correct. Instead of being a view, to you as a member of PUBLIC,

DICTIONARY from your perspective is a synonym. This synonym points

to the SYS-owned view named DICTIONARY, and by the order in which

Oracle resolves an object name, a

public synonym is evaluated before a table or view. If you were to

query against SYS.DICTIONARY, you would be accessing the view named

DICTIONARY owned by SYS.

Closely related to DICTIONARY is a public synonym named DICT.

This synonym is nothing more than a shortcut name for DICTIONARY.

Can you think of another shortcut name of a view in the data

dictionary? The TAB synonym is a pointer to part of what is in the

DBA/ALL/USER_TABLES views. So DICT or DICTIONARY, either one

suffices as both ultimately are derived from several SYS-owned

tables.

The columns of DICTIONARY are table_name and comments. In Oracle

10g R2, there are 659 records, of which, interestingly enough, 91

have no comments. What good is a dictionary without words? Almost

all table name-only records are from the DBA/ALL/USER family (just

an observation, no real reason why they’re from this category).

Where do the comments come from? This is where we start looking

at the underlying tables. The source code behind this view can be

found in the catalog.sql script. The top part of the create view

statement is shown below.

remark

remark VIEW "DICTIONARY"

remark Online documentation for data dictionary tables and views.

remark This view exists outside of the family schema.

remark

create or replace view DICTIONARY

(TABLE_NAME, COMMENTS)

as

select o.name, c.comment$

from sys.obj$ o, sys.com$ c

where o.obj# = c.obj#(+)

and c.col# is null

and o.owner# = 0

and o.type# = 4

...continues...

The OBJ$ table (owned by SYS) is like the uber table of the data

dictionary. Every object has an ID number, an owner number, and a

type number (among other attributes). If OBJ# were a primary key,

we would expect to see primary key type of information about that

column. As it turns out, OBJ# is not the primary key per a “this

column is defined to the primary key for this table.” What does a

primary key have in terms of other constraints? OBJ# does have a

unique index and a not null check constraint, so that must be close

enough from Oracle’s perspective.

The OBJ$ table also has another interesting index related

characteristic, and that is the index named I_OBJ2. This index uses

six columns, which is fairly rare in terms of the number of columns

involved. The vast majority of indexes I see are limited to one,

two or three columns, with the exception of some data warehouse

indexes with five or six columns. All of the objects users create

must be registered in this table, so this is a table that will

continue to grow. How and when are statistics created for the

table? That depends on the version of Oracle you’re using. From

older to newer, the advice or guidance has ranged from “don’t do

it” to “have at it.”

The difference between TYPE# and OWNER# is that the object types

are known ahead of time. Oracle only has so many types, so that

information is static, whereas owners (aside from the internal or

fixed type users of Oracle) come and go. With this difference in

mind, we’d expect to see a lookup table that relates a textual name

versus an owner number. The USER$ table serves this function.

Is there a lookup table for types? We see what the types are in

object tables (the object_type column), but internally, at least as

far as the label versus ID number, Oracle does not have this. So

where does the type name come from? The DECODE of type as seen in

the view creation statements for the _OBJECTS views is what

produces the text labels we see.

Going back to the question posed earlier about where the

comments come from, we can see that a table name COM$ is referenced

in the create dictionary view statement. The COM$ table consists of

OBJ#, COL# and a COMMENT$ columns. In a higher level normalized

form, we’d expect to see a table with OBJ#, COL# and a comment

number or ID, along with a table that then matches the comment

number versus text string or description.

The screenshot below shows how Oracle (at least this table, but

there are others like it) did not go to third normal form. How many

places does a string like “A date function used to compute the

NEXT_DATE” occur? Another string, “Name of the object,” appears 85

times. Doesn’t that clearly violate what every book on database

design and normalization talks about?

Hacking the Data Dictionary

Perhaps you’d be interested in hacking the data dictionary and

adding your own comments into the COM$ table. I wouldn’t recommend

doing that (who would?), so if you wanted to fill in the missing

comments, it would be better to create another view that used a

support table to supply that information (and add your own). If you

were going to do it (using DUAL as an example), find the object

number for DUAL and then use that value for the insert into the

COM$ table.

SQL> select obj#, owner#, name

from obj$ where name = 'DUAL';

OBJ# OWNER# NAME

---------- ---------- ------

258 0 DUAL

259 1 DUAL

9635 24 DUAL

9857 25 DUAL

40433 34 DUAL

40682 35 DUAL

41037 36 DUAL

41990 38 DUAL

42756 43 DUAL

45858 46 DUAL

47876 47 DUAL

50711 51 DUAL

52789 54 DUAL

54234 55 DUAL

52511 56 DUAL

54804 63 DUAL

16 rows selected.

Note that the DUAL table appears more than once, so be sure to

tag the one owned by SYS (the owner number for SYS is zero). When

inserting into the COM$ table, don’t include a COL#. The statement

that creates the DICTIONARY view matches on where the COL# number

is null. The “@dict” script (mine) just selects from DICTIONARY

where the table name is equal to what was entered.

SQL> insert into com$ (obj#,comment$)

values (258,'This the dual table');

1 row created.

SQL> @dict

Enter value for table: dual

TABLE_NAME COMMENTS

------------------------------ --------------------

DUAL This the dual table

The views with missing comments are relatively unimportant, so

performing this hack using existing objects is certainly not

essential. As for adding new lines to the DICTIONARY view via

inserts into the COM$ table, as long as you’re using existing

object numbers, you’re probably safe. Keep track of what you’ve

inserted because if the data dictionary were to be rebuilt, your

work is likely to get overwritten/deleted.

In Closing

Overall, it looks like the data dictionary, specifically, the

SYS schema, is a lot like schemas you encounter in the workplace,

that is, some objects were created “following the rules,” and some

were not. Are queries against the data dictionary faster because

there aren’t lookup tables? Or, is the lack of a lookup table for

comments more of a convenience for the engineers who work on the

SYS schema tables? Regardless, at least now you can reverse

engineer how the dictionary was put together.

oracle查询dictionary,Oracle的DICTIONARY/DICT视图。相关推荐

  1. oracle查询表唯一索引,oracle查询索引(oracle查看表索引)

    oracle查询索引(oracle查看表索引) 2020-07-24 11:01:26 共10个回答 选中表右键View然后查看index 通过PL/SQL可以直接查看某表是否建索引,通过SQL查询s ...

  2. oracle查有哪些数据库,oracle查询数据库(oracle查询所有数据库)

    oracle查询数据库(oracle查询所有数据库) 2020-07-24 12:01:17 共10个回答 PLsql查询工具便可查询 你指所有的表吗?如果你想查数据库中所有的表的话,可以查询sele ...

  3. oracle 查询天,Oracle查询_ 单表查询

    前面我们详解了关于Oracle的增删改,今天让我们接着来学习Oracle的查询吧, Oracle中查询可是重头戏噢!!!跟着煌sir的步伐,走位,走位~~~ 小知识锦囊 在此前,先讲解一个小知识点 O ...

  4. oracle查询快慢,Oracle查询连接数和sql快慢脚本

    Oracle查询连接数和sql快慢脚本 一.查询执行最慢的sql select * from (select sa.SQL_TEXT, sa.SQL_FULLTEXT, sa.EXECUTIONS & ...

  5. Oracle查询数据提示ORA-00942:表或视图不存在

    问题背景 imp导入数据,查询数据提示表不存在,表名是小写的,加了双引号查询是可以的. 查看imp日志,发现导入表,表名是有双引号的!!! 解决方法 ALTER TABLE "aa" ...

  6. oracle查询某个用户下的所有视图

    SYS>select view_name from dba_views where owner = 'NS_RAS3'; VIEW_NAME -------------------------- ...

  7. oracle查询元数据,Oracle Spatial-元数据及SDO_GEOMETRY

    一.空间表的元数据 将表的SDO_GEOMETRY列的所有对象作为一个空间层.Spatial需要对所有空间对象进行验证.创建索引和查询.此时需要为图层指定适当的元数据,该数据包含如下信息:维度.维度边 ...

  8. oracle 查询 ppt,oracle子查询.ppt

    <oracle子查询.ppt>由会员分享,可在线阅读,更多相关<oracle子查询.ppt(26页珍藏版)>请在人人文库网上搜索. 1.子查询,目标,通过本章学习,您将可以: ...

  9. oracle 查询最高分,oracle高级查询

    幕课oracle学习笔记 --!!!scott用户 --一.分组查询 --1.常用的分组函数:AVG(平均数),SUM,MIN,MAX,COUNT,WM_CONCAT(行转列) select avg( ...

  10. oracle查询file_name,Oracle DG环境下db_file_name_convert的实际意义

    关于DG环境下备库数据文件重命名的问题: **前言:** 主要想表明DG环境下备库数据文件重命名的问题,以及db_file_name_convert与log_file_name_convert的作用. ...

最新文章

  1. HDU 1026 Ignatius and the Princess I(BFS)
  2. 子域名枚举工具Sublist3r
  3. 如何正确使用网站TAG标签,让SEO优化效果倍增?
  4. python 源码解析
  5. 单链表头插法与尾插法的c语言实现(回顾)
  6. 阿里巴巴的程序员们来相亲啦!择偶标准大公开,瞬间吸引一众家长
  7. css sprites css精灵
  8. 管理感悟:掌握写文档的技能
  9. 计算机视觉论文-2021-07-13
  10. 设置电脑的背景颜色为保护色
  11. 贝茜放慢脚步(二路归并)
  12. Your actions speak louder
  13. mysql数据库服务器怎么打开_怎么启动mysql数据库服务器
  14. RLC串联电路的谐振相关参数计算
  15. 【国际】塞拉利昂重点发展国家区块链计划
  16. Spyder启动闪退或打开项目编码报错
  17. 5/17/2015 今週日本語勉強の纏め
  18. 社保html源码,社保查询.html
  19. EditText设置IME动作问题
  20. 教python的app_Python教学

热门文章

  1. JZOJ5939. 【NOIP2018模拟10.30】阻击计划
  2. 辽宁教师计算机能力提升,辽宁省中学教师信息化教学能力的现状分析与提升策略研究...
  3. php 正则过滤中英文标点
  4. 飞桨OCR打标、训练、预测、部署全流程
  5. 蓝颜知己的伤感空间日志发布:想你,是一种,刻骨铭心的痛
  6. 毕业从事弱电3个月,我为什么会选择转行网络工程师
  7. 【小程序】766- 一文看懂小程序分享到朋友圈
  8. oppo r5 android 7.1,OPPO R5的手机系统是什么?OPPO R5能升级安卓4.4吗?
  9. 人工智能机器人技术概述
  10. IOS使用高德地图获取当前位置信息