如何用SQL语句获取Oracle表结构
1个回答
展开全部
利用sql语句查询某个表的结构的粗稿掘方法:
通过Oracle中的user_tab_cols, user_col_comments, user_constraints, user_cons_columns表联合查询。
1、user_tab_cols用来获取岩核对应敬羡用户表的列信息;
2、user_col_comments用来获取对应用户表列的注释信息;
3、user_constraints用来获取用户表的约束条件;
4、user_cons_columns约束中用户可访问列。
示例代码:
select t.table_name,
t.column_name,
t.data_type,
t.data_length,
t.nullable,
t.column_id,
c.comments,
(SELECT CASE
WHEN t.column_name = m.column_name THEN
1
ELSE
0
END
FROM DUAL) iskey
FROM user_tab_cols t,
user_col_comments c,
(select m.column_name
from user_constraints s, user_cons_columns m
where lower(m.table_name) = 'qh_outstoresabinfo'
and m.table_name = s.table_name
and m.constraint_name = s.constraint_name
and s.constraint_type = 'P') m
WHERE lower(t.table_name) = 'qh_outstoresabinfo'
and c.table_name = t.table_name
and c.column_name = t.column_name
and t.hidden_column = 'NO'
order by t.column_id
通过Oracle中的user_tab_cols, user_col_comments, user_constraints, user_cons_columns表联合查询。
1、user_tab_cols用来获取岩核对应敬羡用户表的列信息;
2、user_col_comments用来获取对应用户表列的注释信息;
3、user_constraints用来获取用户表的约束条件;
4、user_cons_columns约束中用户可访问列。
示例代码:
select t.table_name,
t.column_name,
t.data_type,
t.data_length,
t.nullable,
t.column_id,
c.comments,
(SELECT CASE
WHEN t.column_name = m.column_name THEN
1
ELSE
0
END
FROM DUAL) iskey
FROM user_tab_cols t,
user_col_comments c,
(select m.column_name
from user_constraints s, user_cons_columns m
where lower(m.table_name) = 'qh_outstoresabinfo'
and m.table_name = s.table_name
and m.constraint_name = s.constraint_name
and s.constraint_type = 'P') m
WHERE lower(t.table_name) = 'qh_outstoresabinfo'
and c.table_name = t.table_name
and c.column_name = t.column_name
and t.hidden_column = 'NO'
order by t.column_id
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |