查询oracle所有的字段,字段注释,类型,长度,精度,小数位,是否外键,是否业务唯一键,是否分布键值,是否主键,是否可空,分区字段,是否码值,码值注释,字段备注,表名,表注释,
时间: 2023-07-21 08:13:56 浏览: 151
这是一个比较复杂的问题,需要使用 SQL 语句来查询 Oracle 数据库的系统表。以下是一个示例 SQL 语句,可以查询表、列的详细信息:
```
SELECT
cols.column_name AS 字段名称,
cols.comments AS 字段注释,
cols.data_type AS 字段类型,
cols.data_length AS 字段长度,
cols.data_precision AS 字段精度,
cols.data_scale AS 小数位,
decode(con.constraint_type, 'P', '是', '否') AS 是否主键,
decode(con.constraint_type, 'U', '是', '否') AS 是否业务唯一键,
decode(con.constraint_type, 'R', '是', '否') AS 是否外键,
decode(cols.partition_key, 'YES', '是', '否') AS 是否分区字段,
decode(cols.nullable, 'Y', '是', '否') AS 是否可空,
cols.column_id AS 字段顺序,
cols.table_name AS 表名,
tabs.comments AS 表注释,
decode(mv.referenced_name, null, '否', '是') AS 是否码值,
mv.comments AS 码值注释,
cols.data_default AS 字段备注
FROM
user_tab_columns cols
LEFT JOIN user_tab_comments tabs ON cols.table_name = tabs.table_name
LEFT JOIN user_cons_columns cols_con ON cols.table_name = cols_con.table_name AND cols.column_name = cols_con.column_name
LEFT JOIN user_constraints con ON cols_con.constraint_name = con.constraint_name AND cols.table_name = con.table_name
LEFT JOIN (
SELECT
cols.table_name,
cols.column_name,
con.r_owner AS referenced_owner,
con.r_constraint_name AS referenced_name
FROM
user_cons_columns cols
LEFT JOIN user_constraints con ON cols.owner = con.owner AND cols.constraint_name = con.constraint_name
WHERE
con.constraint_type = 'R'
) mv ON cols.table_name = mv.table_name AND cols.column_name = mv.column_name
WHERE
cols.table_name NOT LIKE 'BIN$%'
ORDER BY
cols.table_name,
cols.column_id;
```
注意,这个 SQL 语句可能需要根据实际情况进行调整,比如修改表名的过滤条件。同时,需要有足够的权限才能查询系统表。
阅读全文