2012-12-14 37 views
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的表格。所以我需要做一個查詢,告訴我哪些列丟失,任何人都可以幫我做一個查詢。如果你需要任何信息,請隨時問我會給任何必要的信息。

回答

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 
+0

@ DazzaL。這是有益的,謝謝這是很大的幫助.... – Auguster