数据字典一般需要 表名、表中文名、字段名、字段中文名、字段数据类型、字段中文名、是否主键这几列。具体获取逻辑如下。 (需将过滤条件中的用户改为自己指定的用户)
select
t.owner, --用户
t.table_name, --表英文名
tc.comments, --表中文名
c.column_id, --字段序号
c.column_name,--字段英文名
c.data_type||case c.data_type
when 'number' then '('||c.data_length||','||c.data_scale||')'
when 'timestamp' then ''
when 'date' then ''
else '('||c.data_length||')'
end as data_type, --数据类型,
cc.comments as col_comments, case when co.column_name is not null then 'y' else 'n' end as prim_flg --是否主键
from all_tables t --表基本信息
left join all_tab_comments tc --表中文名
on t.table_name =tc.table_name
and t.owner =tc.owner
left join all_tab_columns c --字段基本信息
on t.table_name =c.table_name
and t.owner =c.owner
left join all_col_comments cc --字段中文名
on c.column_name = cc.column_name
and c.table_name =cc.table_name
and c.owner = cc.owner
left join all_constraints aco --获取表主键约束
on t.table_name =aco.table_name
and t.owner =aco.owner
and aco.constraint_type = 'p'
left join all_cons_columns co --获取主键约束对应字段
on c.owner =co.owner
and c.table_name=co.table_name
and c.column_name = co.column_name
and aco.constraint_name = co.constraint_name
where t.owner ='指定用户'
order by t.owner,t.table_name,c.column_id
查询结果如下:
具体需求个人情况适当修改。
如:字段类型这一列我只考虑了常用的那几类
表约束中除了有主键约束还有非空约束 等等