您好,欢迎访问一九零五行业门户网

Oracle查询数据表结构(字段,类型,大小,备注)

创建表的sql语句如下 -- 创建数据表 create table table_test ( name varchar2(40) not null, sex varchar2(1) default ''''y'''' not null, birthday date not null, height number(3,2), weight number(3,2), memo blob ); -- 给列添加备注 comment on col
创建表的sql语句如下
-- 创建数据表
create table table_test
(
    name varchar2(40) not null,
    sex varchar2(1) default ''''y'''' not null,
    birthday date not null,
    height number(3,2),
    weight number(3,2),
    memo blob
);
-- 给列添加备注
  comment on column table_test.name is ''''姓名'''';
  comment on column table_test.sex is ''''性别'''';
  comment on column table_test.birthday is ''''生日'''';
  comment on column table_test.height is ''''身高'''';
  comment on column table_test.weight is ''''体重'''';
  comment on column table_test.memo is ''''备注'''';
-- 创建约束关系 主键 外键 其他
  alter table table_test add constraint tb_test_p_name primary key (name);
数据表创建完毕,执行下列sql语句:
select
    a.column_name 字段名,a.data_type 数据类型,a.data_length 长度,a.data_precision 整数位,
    a.data_scale 小数位,a.nullable 允许空值,a.data_default 缺省值,b.comments 备注
from
    user_tab_columns a,user_col_comments b
where
    a.table_name = b.table_name
    and a.column_name = b.column_name
    and a.table_name = ''''table_test''''
我们可以得出一下结果:
字段名

数据类型

长度

整数位

小数位

允许空值

缺省值

备注

name

varchar2



40











































n

















姓名

sex

varchar2



1













































n

















性别

birthday

date

7











































n

















生日

height

number



22



3



2




y

















身高

weight

number



22



3



2




y

















体重

memo

blob

4000











































y

















备注

这样,我们在进行程序设计时,通过一条简单的sql语句,然好通过ole调用word,便可为最终用户导出完整的数据库表字典文档。
再执行下列sql语句:
select
    index_name 索引名,index_type 索引类型,uniqueness 索引类别
from
    user_indexes
where
    table_name = ''''table_test''''
得到结果如下(注:sys_il0000031226c00006$$索引为系统在创建数据库表时自动创建的,用于数据库表内容的维护):

索引名
索引类型
索引类别
1



sys_il0000031226c00006$$
lob
unique

2




tb_test_p_name
normal
unique

执行下列sql语句,我们将得到更多的关于数据库表结构的信息:
select
    a.column_name 字段名,a.data_type 数据类型,a.data_length 长度,a.data_precision 整数位,
    a.data_scale 小数位,a.nullable 允许空值,a.data_default 缺省值,b.comments 备注,
    c.indexcount 索引次数
from
    user_tab_columns a,
    user_col_comments b,
    (select count(*) indexcount,column_name from user_ind_columns where table_name = ''''table_test'''' group by column_name) c
where
    a.table_name = b.table_name
    and a.column_name = b.column_name
    and a.column_name = c.column_name(+)
    and a.table_name = ''''table_test''''
得到结果如下:
字段名

数据类型

长度

整数位

小数位

允许空值

缺省值

备注

索引次数
birthday

date

7











































n

















生日






















height

number



22



3



2




y

















身高






















memo

blob

4000











































y

















备注






















name

varchar2



40











































n

















姓名

1



sex

varchar2



1













































n

















性别






















weight

number



22



3



2




y

















体重






















当然oracle数据字典的应用远不止这些,通过oracle数据库字典的支持,我们可以得到oracle数据库结构的所有信息,著名的数据库开发工具pl/sql developer完全就是基于oracle的数据库字典实现的。
其它类似信息

推荐信息