将 oracle 数据库中所有用户表的表结构导出,并存储到 excel 表中,存储信息如下图所示:
问题描述:
将 oracle 数据库中所有用户表的表结构导出,并存储到 excel 表中,存储信息如下图所示:
select a.table_name,a.comments,b.column_name,b.comments from user_tab_comments a,user_col_comments b where a.table_name = b.table_name
解决方案:
1) 启动 pl/sql ,应用需要导出表结构的用户登录目标数据库实例
2) new-sql window 创建查询窗口
3) 在查询窗口中输入以下查询语句:
select t.table_name 表名 ,t.column_id 序号 ,t.column_name 字段名 ,t.data_type 类型 ,t. data_length 长度 ,t.nullable 是否为空
from user_tab_columns t
其中 user_tab_columns 为当前用户表结构信息表。
4) 只想完成后,在查询窗口中点击按钮显示所有记录信息
5) 右键 -copy to excel ,将查询信息保存到 excel 中
6) 通过 excel 中打开保存的查询结果数据,选择数据 - 筛选,,选择不同的表,然后可以取出不同表的表结构
7) 如果在查询过程中选择特定表的表结构则执行以下语句
select t.table_name 表名 ,t.column_id 序号 ,t.column_name 字段名 ,t.data_type 类型 ,t. data_length 长度 ,t.nullable 是否为空
from user_tab_columns t
where table_name=’ 表名 ’
注:这里的表名,需要查询的表名替换,比如 user 表则写成: where table_name=’user’
经验总结:
1) 数据表 user_tab_columns 中存储了当前用户所有数据表的表结构。
2) 数据表 all_tab_columns 中存储了当前数据库实例中所有数据表的表结构。
3) 数据表 all_tab_columns 和数据表 user_tab_columns 的区别在于表 all_tab_columns 多了一个 owner 字段,用来存储表所属的用户。
通过 pl/sql 可以将查询结果直接导出到 excel 文件中。