oracle 数据字典画报,Oracle 数据字典查询

1.查询表的相关信息

查询结果如下:

0e67b7b955a44dd613288494e86259bf.png

9a69c34dc7b4db445690f74183d3b261.png

查询脚本如下:

select tt1.owner,

tt1.table_name,

tt1.comments,

tt1.last_analyzed,

tt1.num_rows,

tt2.colcnt

from (select t1.owner,

t1.table_name,

c1.comments,

t1.last_analyzed,

t1.num_rows

from all_tables t1, ALL_TAB_COMMENTS c1

where t1.owner = c1.owner

and t1.table_name = c1.table_name) tt1,

(select t5.OWNER, t5.TABLE_NAME, count(1) as colcnt

from dba_tab_columns t5

where t5.OWNER not in

('SYS', 'SYSTEM', 'OUTLN', 'DIP', 'ORACLE_OCM', 'DBSNMP',

'APPQOSSYS', 'WMSYS', 'EXFSYS', 'CTXSYS', 'XDB', 'ANONYMOUS',

'ORDSYS', 'ORDDATA', 'ORDPLUGINS', 'SI_INFORMTN_SCHEMA',

'MDSYS', 'OLAPSYS', 'MDDATA', 'SPATIAL_WFS_ADMIN_USR',

'SPATIAL_CSW_ADMIN_USR', 'SYSMAN', 'MGMT_VIEW', 'FLOWS_FILES',

'APEX_PUBLIC_USER', 'APEX_030200', 'OWBSYS', 'OWBSYS_AUDIT',

'SCOTT', 'HR', 'OE', 'IX', 'SH', 'PM', 'BI', 'XS$NULL')

group by t5.OWNER, t5.TABLE_NAME) tt2

where tt1.owner = tt2.owner

and tt1.table_name = tt2.table_name

order by tt1.owner, tt1.table_name

2.查询字段相关信息

查询结果如下:

0b04062ce6c98d284a43c7fdc9d9c720.png

73d573404f611f98fbcdd596d8b1f49a.png

查询脚本如下:

select ttt1.owner,

ttt1.table_name,

ttt1.column_name,

ttt1.DATA_TYPE,

ttt1.comments,

(case ttt2.constraint_type

when 'P' THEN

'Y'

ELSE

'N'

END) "是否主键",

(case ttt3.constraint_type

when 'R' THEN

'Y'

ELSE

'N'

END) "是否外键",

(case ttt4.constraint_type

when 'U' THEN

'Y'

ELSE

'N'

END) "是否唯一值",

ttt1.NULLABLE

from (select tt1.owner,

tt1.table_name,

tt1.column_name,

tt1.DATA_TYPE,

tt1.COLUMN_ID,

tt2.comments,

tt1.NULLABLE

from (select t2.owner,

t2.table_name,

t2.column_name,

t2.DATA_TYPE,

t2.COLUMN_ID,

t2.NULLABLE

from all_tab_columns t2

where t2.owner not in

('SYS', 'SYSTEM', 'OUTLN', 'DIP', 'ORACLE_OCM',

'DBSNMP', 'APPQOSSYS', 'WMSYS', 'EXFSYS', 'CTXSYS',

'XDB', 'ANONYMOUS', 'ORDSYS', 'ORDDATA', 'ORDPLUGINS',

'SI_INFORMTN_SCHEMA', 'MDSYS', 'OLAPSYS', 'MDDATA',

'SPATIAL_WFS_ADMIN_USR', 'SPATIAL_CSW_ADMIN_USR',

'SYSMAN', 'MGMT_VIEW', 'FLOWS_FILES',

'APEX_PUBLIC_USER', 'APEX_030200', 'OWBSYS',

'OWBSYS_AUDIT', 'SCOTT', 'HR', 'OE', 'IX', 'SH', 'PM', 'BI',

'XS$NULL')) tt1,

ALL_COL_COMMENTS tt2

where tt1.owner = tt2.owner

and tt1.table_name = tt2.table_name

and tt1.column_name = tt2.column_name) ttt1

left join

(select col.owner, col.table_name, col.column_name, con.constraint_type

from all_constraints con, all_cons_columns col

where con.constraint_name = col.constraint_name

and con.owner = col.owner

and con.table_name = col.table_name

and con.constraint_type = 'P') ttt2 on ttt1.owner = ttt2.owner

and ttt1.table_name =

ttt2.table_name

and ttt1.column_name =

ttt2.column_name

left join

(select col.owner, col.table_name, col.column_name, con.constraint_type

from all_constraints con, all_cons_columns col

where con.constraint_name = col.constraint_name

and con.owner = col.owner

and con.table_name = col.table_name

and con.constraint_type = 'R') ttt3 on ttt1.owner = ttt3.owner

and ttt1.table_name =

ttt3.table_name

and ttt1.column_name =

ttt3.column_name

left join

(select col.owner, col.table_name, col.column_name, con.constraint_type

from all_constraints con, all_cons_columns col

where con.constraint_name = col.constraint_name

and con.owner = col.owner

and con.table_name = col.table_name

and con.constraint_type = 'U') ttt4 on ttt1.owner = ttt4.owner

and ttt1.table_name =

ttt4.table_name

and ttt1.column_name =

ttt4.column_name

order by ttt1.owner, ttt1.table_name, ttt1.COLUMN_ID

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值