使用Oracle导出数据字典
目的:
- 编写文档用
准备:
- PL/SQL Developer
方法: 使用 SQL 查询, 然后导出
SQL 脚本
select TABLE_NAME from user_tables; -- 查询当前用户的表
select * from user_tab_comments; -- 查询表的注释
select * from User_Col_Comments; -- 查询列注释
导出表
-- 导出文档
SELECT
t.TABLE_NAME 表名,
t.COLUMN_NAME 列名,
REPLACE (
REPLACE ( REPLACE ( t1.COMMENTS, chr( 10 ), '' ), chr( 13 ), '' ),
chr( 9 ),
''
) 描述,
t.DATA_TYPE 数据类型,
t.DATA_LENGTH 数据长度,
t.NULLABLE 可否为空,
case when t.COLUMN_NAME = 'ID' THEN '是' else '否' end 是否为ID,
REPLACE (
REPLACE ( REPLACE ( t1.COMMENTS, chr( 10 ), '' ), chr( 13 ), '' ),
chr( 9 ),
''
) 注释
FROM
user_tab_columns t,
User_Col_Comments t1
WHERE
t.TABLE_NAME =t1.TABLE_NAME
and t1.column_name = t.COLUMN_NAME
and t.TABLE_NAME IN (select TABLE_NAME from user_tables) --表名 需要修改
ORDER BY
t.TABLE_NAME,
t.COLUMN_NAME;
这里注意, PL/SQL Developer 会对结果集分页