Oracle中SQL查询表字段基本信息、主键、外键(转)
select utc.column_name, utc.data_type, utc.data_length, utc.data_precision, utc.data_Scale, utc.nullable, utc.data_default, ucc.comments, utc.table_name from user_tab_columns utc, user_col_comments ucc where utc.table_name = ucc.table_name and utc.column_name = ucc.column_name and utc.table_name in (select upper(tb.table_name) from all_tables tb where tb.OWNER = 'USER_NAME') order by column_id
注意:order by column_id的意义是使得结果按照设计数据结构时的顺序显示。
二,查询表主键
select
col.column_name
from
user_constraints con,user_cons_columns col
where
con.constraint_name=col.constraint_name and con.constraint_type='P'
and col.table_name='ONLINEXLS'
三,查询表外键
select
distinct(ucc.column_name) column_name,rela.table_name,rela.column_name column_name1
from
user_constraints uc,user_cons_columns ucc,
(select t2.table_name,t2.column_name,t1.r_constraint_name from user_constraints t1,user_cons_columns t2 where t1.r_constraint_name=t2.constraint_name and t1.table_name='ONLINEXLS') rela
where
uc.constraint_name=ucc.constraint_name
and uc.r_constraint_name=rela.r_constraint_name
and uc.table_name='ONLINEXLS'
有了上述几个SQL语句,再结合程序(如:java+jxl),就可以输出如下图所示的Excel报表了。
本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2011-08/41830.htm
posted on 2013-12-12 14:48 四海皆兄弟2011 阅读(1429) 评论(0) 编辑 收藏 举报