1

嗨,我需要将一组表的列与另一组表进行比较。让我解释一下结构。第二组表取自第一个表,列数较少。

TABLE NAMES:
W_table_1_fact
W_tables_2_fact
.........
........
W_table_n_dim
W_table_1_dim
W_tables_2_dim
.........
........
W_table_n_dim


ABC_W_table_1_fact
ABC_W_tables_2_fact
.........
........
ABC_W_table_n_dim
ABC_W_table_1_dim
ABC_W_tables_2_dim
.........
........
ABC_W_table_n_dim

现在带有前缀 ABC 的表的数据和列取自原始表,除了少数缺失的列和可能的一些数据(现在不关心)。我需要检查我们需要的列是否已加载到带有前缀 ABC 的表。所以我需要进行查询,告诉我缺少哪些列,任何人都可以帮我查询。如果您需要任何信息,请随时询问我会提供任何所需的信息。

4

1 回答 1

2

所以你想查看源中的列(不是数据),而不是整个表列表的目标?你可以为此在 USER_TAB_COLUMNS 上做一个 MINUS。例如:

with tables as
 (select table_name t1, 'ABC_'||table_name t2 --<--- prefixed table 2 based on tables name
    from user_tables 
   where table_name in ('W_TABLE_1_FACT', 'W_TABLES_2_FACT' ))
select t.*,
       cursor (select column_name
                  from user_tab_columns
                 where table_name = t.t1
                minus
                select column_name 
                  from user_tab_columns 
                 where table_name = t.t2) missing_columns
  from tables t
于 2012-12-14T16:35:21.427 回答