oracle中,如何利用sql语句查询某个表的结构?

oracle中,如何利用sql语句查询某个表的结构?比如,已知某个表名是test,但不知道这张表有哪些字段,怎么查(不能用 select * from test方式)?
楼下的朋友,我试过 desc test,在命令行里是可以的,但我需要把表结构给一个rs,这样方便我使用.

  利用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
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-02-14
oracle
下读取表/字段的备注信息
oracle
通过comment
on
table
/
comment
on
column
追加表/字段的备注。
create
table
"mr_dept"
(
"dept_id"
number
not
null
,
"parent_id"
number,
"dept_name"
char(20)
not
null
,
"status"
number
default
1
not
null
,
primary
key
("dept_id")
);
comment
on
table
"mr_dept"
is
'部门表';
comment
on
column
"mr_dept"."dept_id"
is
'部门编号';
comment
on
column
"mr_dept"."parent_id"
is
'上级部门编号';
comment
on
column
"mr_dept"."dept_name"
is
'部门名';
comment
on
column
"mr_dept"."status"
is
'状态';
备注加好以后,如何在查询中检索呢?
查询表的备注信息
select
table_name,
table_type,
comments
from
user_tab_comments
where
table_name
=
'mr_dept;
查询字段的备注信息
select
table_name,
column_name,
comments
from
user_col_comments
where
table_name
=
'mr_dept;
第2个回答  2019-06-16
  利用
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
第3个回答  2006-11-20
rs不知是什么东西..
用sql语句行不行?
select COLUMN_NAME,DATA_TYPE from USER_TAB_COLS where TABLE_NAME='TEST';本回答被提问者采纳
第4个回答  2006-11-19
desc test
相似回答