如何在 Oracle 中通过 SQL 获取表注释?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16567129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get table comments via SQL in Oracle?
提问by Tristan
I've tried :
我试过了 :
select * from user_tab_comments;
and it returns me 3 columns "TABLE_NAME", "TABLE_TYPE", and "COMMENTS", but the "TABLE_NAME" column is like "encrypted", I need clear table names :
它返回 3 列“TABLE_NAME”、“TABLE_TYPE”和“COMMENTS”,但“TABLE_NAME”列就像“加密”,我需要明确的表名:
TABLE_NAME TABLE_TYPE COMMENTS
BIN$IN1vjtqhTEKcWfn9PshHYg==select * from all_tab_comments
where substr(table_name,1,4) != 'BIN$'
/
TABLE Résultat d'intégration d'une photo numérisée
BIN$PUwG3lb3QoazOc4QaC1sjw==select tc.*
from all_tab_comments tc
join all_tables t
on tc.owner = t.owner
and tc.table_name = t.table_name
where t.dropped = 'NO'
/
TABLE Motif de fin d'agrément de ma?tre de stage
When I use select * from user_tables;
TABLE_NAME is not "encrypted".
当我使用select * from user_tables;
TABLE_NAME 时没有“加密”。
回答by APC
Since 10g Oracle doesn't immediately drop tables when we issue a DROP TABLE statement. Instead it renames them like this BIN$IN1vjtqhTEKcWfn9PshHYg==$0
and puts them in the recycle bin. This allows us to recover tables we didn't mean to drop. Find out more.
由于 10g Oracle 在我们发出 DROP TABLE 语句时不会立即删除表。相反,它像这样重命名它们BIN$IN1vjtqhTEKcWfn9PshHYg==$0
并将它们放入回收站。这允许我们恢复我们不打算删除的表。 了解更多。
Tables in the recycle bin are still tables, so they show up in ALL_TABLES and similar views. So if you only want to see comments relating only to live (non-dropped) tables you need to filter by table name:
回收站中的表仍然是表,因此它们显示在 ALL_TABLES 和类似视图中。因此,如果您只想查看仅与活动(未删除)表相关的评论,则需要按表名进行过滤:
##代码##"I can't believe there isn't a flag column so you could do and is_recycled = 0 or something. "
“我不敢相信没有标志栏,所以你可以做 is_recycled = 0 或其他什么。”
You're right, it would be incredible. So I checked the documentation it turns out Oracle 10g added a column called DROPPED to the USER_/ALL_/DBA_TABLES views.
你是对的,这将是不可思议的。因此,我查看了文档,结果发现 Oracle 10g 在 USER_/ALL_/DBA_TABLES 视图中添加了一个名为 DROPPED 的列。
##代码##Check out the documentation. Obviously the need to join to the ALL_TABLES view requires more typing than filtering on the name, so depending on our need it might just be easier to keep the original WHERE clause.
查看文档。显然,需要加入 ALL_TABLES 视图需要更多的输入而不是过滤名称,因此根据我们的需要,保留原始 WHERE 子句可能更容易。
回答by Gank
SELECT t.table_name,t.comments FROM USER_TAB_COMMENTS t WHERE TABLE_NAME = 'SS_DEPT';
SELECT t.table_name,t.comments FROM USER_TAB_COMMENTS t WHERE TABLE_NAME = 'SS_DEPT';