oracle获取当前用户表、字段等详细信息SQL
做个笔记,仅供参考SELECT
d.TABLE_NAME tbName,//表名
COALESCE(t.COMMENTS, ' ') tbDesc, //表注释
a.COLUMN_NAME columnName, //字段名
a.DATA_TYPE columnType, //字段类型
a.DATA_LENGTH width, //字段长度
a.DATA_SCALE precision,//字段小数位
decode(a.NULLABLE,'Y','0','1') notNull,//是否允许空
COALESCE(m.COMMENTS, ' ') comments, //字段备注
decode(k.uniqueness,'UNIQUE','1','0') uniques, //是否唯一
COALESCE(k.index_name, ' ') indexName,//如果是索引,索引名
decode(k.key,'Y','1','0') masterKey//是否主键
FROM
user_tab_columns a
INNER JOIN user_tables d on a.TABLE_NAME=d.TABLE_NAME
LEFT JOIN user_tab_comments t ON t.TABLE_NAME=d.TABLE_NAME
LEFT JOIN user_col_comments m ON m.COLUMN_NAME=a.COLUMN_NAME AND m.TABLE_NAME=d.TABLE_NAME
LEFT JOIN
(
SELECT e.index_name,u.TABLE_NAME,u.COLUMN_NAME,e.uniqueness,decode(p.constraint_name,NULL,'N','Y') key
from user_indexes e INNER JOIN user_ind_columns u ON e.index_name=u.index_name
LEFT JOIN ( select constraint_name from user_constraints where constraint_type='P' ) p ON e.index_name=p.constraint_name
) k ON k.TABLE_NAME=a.TABLE_NAME and k.COLUMN_NAME=a.COLUMN_NAME
ORDER BY tbName备注:user_开头是当前用户,all_开头所有用户,dba_开头包括系统表
https://www.uoften.com/dbs/oracle/20180415/73210.html
页:
[1]