SELECT
-- 获取字段名
t1.Table_Name AS "数据库字段名",
-- 获取表注释(这里假设表注释存放在USER_TAB_COMMENTS视图中,你可能需要根据实际情况调整所属用户等条件)
t3.comments AS "表注释",
CASE WHEN pk.column_name IS NOT NULL THEN '是' ELSE '否' END AS "是否主键",
t1.Table_Name || chr(13) || t3.comments AS "表名称及说明",
--t3.comments AS "表说明",
t1.Column_Name AS "字段名称",
t1.DATA_TYPE || '(' || t1.DATA_LENGTH || ')' AS "数据类型",
-- 判断是否允许为空
CASE WHEN t1.NullAble = 'Y' THEN '是' ELSE '否' END AS "是否为空",
t2.Comments AS "字段说明",
t1.Data_Default "默认值"
-- t4.created AS "建表时间"
FROM cols t1
LEFT JOIN user_col_comments t2
ON t1.Table_name = t2.Table_name
AND t1.Column_Name = t2.Column_Name
LEFT JOIN user_tab_comments t3
ON t1.Table_name = t3.Table_name
LEFT JOIN user_objects t4
ON t1.table_name = t4.OBJECT_NAME
-- 关联主键相关视图判断是否主键
LEFT JOIN (
SELECT
cc.column_name,
cc.table_name
FROM
user_constraints c
JOIN user_cons_columns cc ON c.constraint_name = cc.constraint_name
WHERE
c.constraint_type = 'P'
) pk ON t1.column_name = pk.column_name AND t1.table_name = pk.table_name
WHERE NOT EXISTS (SELECT t4.Object_Name
FROM User_objects t4
WHERE t4.Object_Type = 'TABLE'
AND t4.Temporary = 'Y'
AND t4.Object_Name = t1.Table_Name
)
and t1.TABLE_NAME='你要查询的表' --这里注意哦换成自己要查的那个表的表名,如果去掉这句话会查出该数据库所有的表结构
ORDER BY t1.Table_Name, t1.Column_ID;
--以上所查的列如果不符合自己的要求 可以通过自己更改sql语句来获得想要查询的列,想要的属性上面几张系统表里都有,自己写也很简单
查询oracle数据库的表结构,数据库字段名、表字段注释、 表字段属性、是否主键等
于 2025-01-10 09:34:38 首次发布