Oracle,如何获取 COMMENTS 不为空且具有特定列的表

Oracle, How can I get tables where COMMENTS is not null and has specific column

我想获取包含 'CUST_ID' 列且其注释不为空的表。

获取表 column_name 'CUST_ID'

SELECT TABLE_NAME FROM USER_TAB_COLUMNS WHERE COLUMN_NAME='CUST_ID';

获取评论不为空的表

SELECT TABLE_NAME, COMMENTS FROM user_tab_comments WHERE COMMENTS IS NOT NULL;

如何获取两个注释都不为空且具有 column_name 'CUST_ID' 的表?

我试过了

SELECT count(*) FROM USER_TAB_COLUMNS, USER_TAB_COMMENTS 
      WHERE USER_TAB_COLUMNS.column_name='CUST_ID' 
        and USER_TAB_COMMENTS.COMMENTS IS NOT NULL;

但是没用。

您可以加​​入两个查询:

SELECT col.table_name, com.comment
FROM   user_tab_columns col
JOIN   user_tab_comments com ON col.table_name = com.table_name
WHERE  col.column_name = 'CUST_ID' AND 
       com.comments IS NOT NULL;