Sql 比较多个表的列,一组表具有前缀,并且列数少于另一组表
嗨,我需要比较一组表和另一组表的列。让我解释一下结构。第二组表是从第一组表中提取的,列数较少Sql 比较多个表的列,一组表具有前缀,并且列数少于另一组表,sql,oracle10g,Sql,Oracle10g,嗨,我需要比较一组表和另一组表的列。让我解释一下结构。第二组表是从第一组表中提取的,列数较少 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_
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的表中。因此,我需要进行一个查询,告诉我缺少哪些列。任何人都可以帮助我进行查询。如果您需要任何信息,请随时询问。我将提供任何所需信息。因此您希望查看列(而不是数据)在源中,但不是整个表列表的目标?您可以对用户选项卡列进行减号。例如:
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
将表作为
(选择表格名称t1,‘ABC’| |表格名称t2--