利用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, ments, (SELECT CASE WHEN t.column_name = m.column_name THEN 1 ELSE 0ENDFROM DUAL) iskey FROM user_tab_cols t, user_col_comments c, (select m.column_namefrom 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