Oracle查询表字段信息及注释

Oracle查询表字段信息及注释,第1张

查询字段信息:

SELECT * FROM all_tab_columns WHERE OWNER = 'OWNER_NAME' AND TABLE_NAME='TABLE_NAME'

-- 或者

SELECT * FROM user_tab_columns WHERE TABLE_NAME='TABLE_NAME'

查询字段注释:

SELECT * FROM all_col_comments WHERE TABLE_NAME='TABLE_NAME'

--或者

SELECT * FROM user_col_comments WHERE TABLE_NAME='TABLE_NAME'

合起来查询:

注意:查询结果中,字段非空是 ‘N’,可为空是 ‘Y’

SELECT 
  a.OWNER 模式,
  a.TABLE_NAME 表名, 
  a.COLUMN_NAME 列名, 
  a.DATA_TYPE 数据类型, 
  a.DATA_LENGTH 长度, 
  a.NULLABLE 非空, 
  --(CASE WHEN a.NULLABLE = 'N' THEN 'Y' ELSE 'N' END) 非空,
  b.COMMENTS 注释
FROM all_tab_columns a
LEFT JOIN all_col_comments b ON a.OWNER = b.OWNER AND a.TABLE_NAME = b.TABLE_NAME AND a.COLUMN_NAME = b.COLUMN_NAME
WHERE a.OWNER = 'OWNER_NAME' AND a.TABLE_NAME = 'TABLE_NAME '
ORDER BY a.TABLE_NAME, a.COLUMN_ID

--或者

SELECT 
  a.TABLE_NAME 表名, 
  a.COLUMN_NAME 列名, 
  a.DATA_TYPE 数据类型, 
  a.DATA_LENGTH 长度, 
  a.NULLABLE 非空, 
  --(CASE WHEN a.NULLABLE = 'N' THEN 'Y' ELSE 'N' END) 非空,
  b.COMMENTS 注释
FROM user_tab_columns a
LEFT JOIN user_col_comments b ON a.TABLE_NAME = b.TABLE_NAME AND a.COLUMN_NAME = b.COLUMN_NAME
WHERE a.TABLE_NAME = 'TABLE_NAME '
ORDER BY a.COLUMN_ID

另,查询表注释:

SELECT * FROM user_tab_comments WHERE TABLE_NAME='CODE_GENERAL'

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/991518.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存