oracle查看表的字段,主键,外键和字段类型

在查询时,注意表的名字需要全部大写
1.查询表的字段

SELECT column_name FROM user_tab_columns where table_name = upper('表名') ;

2.查询表的字段以及类型

SELECT table_name, column_name, data_type FROM all_tab_cols WHERE table_name = '表名';

3.查询表的主键

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='表名';

4.查询表的外键

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='BBSDETAIL') rela
 where  uc.constraint_name=ucc.constraint_name
 and uc.r_constraint_name=rela.r_constraint_name
 and uc.table_name='表名';

5…Oracle获取表字段名,字段类型,字段长度,注释

SELECT b.comments as 注释,
       a.column_name as 列名,
       a.data_type || '(' || a.data_length || ')' as 数据类型,
       a.nullable as 是否为空
  FROM user_tab_columns a, user_col_comments b
 WHERE a.TABLE_NAME = '表名'
   and b.table_name = '表名'
   and a.column_name = b.column_name;

你可能感兴趣的:(oracle)