ORACLE MINUS 关键字的 ANSI SQL 标准

Posted

技术标签:

【中文标题】ORACLE MINUS 关键字的 ANSI SQL 标准【英文标题】:ANSI SQL standard for ORACLE MINUS keyword 【发布时间】:2014-11-21 11:59:38 【问题描述】:

我有 Query,我想与 ANSI SQL 标准兼容。在这个 使用 oracle 查询 MINUS 键工作,我想要 ANSI SQL,它是 放置在 MINUS 关键字上

SELECT   'F' selected,
         UPPER ((   a.business
                 || ' '
                 || a.data_source
                 || ' '
                 || a.frequency
                 || ' '
                 || a.case_symbol
                )
               ) AS display_name,
         SUBSTR ((   a.business
                  || '_'
                  || a.data_source
                  || '_'
                  || a.frequency
                  || (CASE
                         WHEN a.case_symbol IS NULL
                            THEN ''
                         ELSE '_' || a.case_symbol
                      END
                     )
                 ),
                 0,
                 30
                ) AS summary_schema_name,
                 (SELECT ef.frequency_name
            FROM etl_frequencies@etlmgr_srv_ubatchh_lx ef
           WHERE ef.frequency = a.frequency) data_frequency_name,
         a.case_symbol subset_key, '' subset_name
    FROM (SELECT DISTINCT ebdf.business, ebdf.data_source, ebdf.frequency,
                          c.case_symbol
                     FROM  etl_bus_datasrc_frequencies@etlmgr_srv_ubatchh_lx ebdf INNER JOIN etl_rulesets@etlmgr_srv_ubatchh_lx er
                          ON (    ebdf.business = er.business
                              AND ebdf.data_source = er.data_source
                              AND ebdf.frequency = er.frequency
                             )
                          LEFT OUTER JOINe etl_db_output_fact_rules@etlmgr_srv_ubatchh_lx r
                          ON er.ruleset_id = r.ruleset_id
                          LEFT OUTER JOIN etl_db_output_fact_cases@etlmgr_srv_ubatchh_lx c
                          ON r.db_output_fact_rule_id =
                                                      c.db_output_fact_rule_id
          MINUS
          SELECT c.business_unit_key, e.data_source_key, f.data_frequency_key,
                 g.data_source_subset
            FROM  tb_module_summary_schema a INNER JOIN  tb_module b
                 ON a.module = b.module
                 INNER JOIN  tb_business_unit c
                 ON b.business_unit_id = c.business_unit_id
                 INNER JOIN  tb_summary_source_type d
                 ON a.summary_source_type_id = d.summary_source_type_id
                 INNER JOIN  tb_data_source e
                 ON d.data_source_id = e.data_source_id
                 INNER JOIN  tb_data_frequency f
                 ON d.data_frequency_id = f.data_frequency_id
                 LEFT OUTER JOIN  tb_data_source_subset g
                 ON d.data_source_subset_id = g.data_source_subset_id
                 ) a
ORDER BY a.business, a.data_source, a.frequency, a.case_symbol   

【问题讨论】:

那就是except minus 改为except 关键字后,在Oracle 中无法继续运行此查询,您真正遇到了什么问题? EXCEPT 在 Oracle 中不起作用,因此如果您希望它符合 ANSI SQL 并在 Oracle 中运行,您必须使用“NOT EXISTS”或“NOT IN”构造重写查询 我希望此查询与 ANSI SQL 92 兼容,但 MINUS 关键字对我来说是一个障碍。 让我们澄清一下,您不希望此查询在 Oracle 中可执行,您希望此查询与 ANSI-92 标准兼容,或者您​​希望重写此查询以与 ANSI-兼容92并且要在Oracle中执行,你需要什么? 【参考方案1】:

查看外连接

Doing INTERSECT and MINUS in mysql

【讨论】:

链接失效【参考方案2】:
select <columns>
  from (
        select 'SRC' as data_source, <columns>
          from source_table 
         union all
        select 'TRG' as data_source, <columns>
         from target_table
       )
 group by <columns>
having max(data_source) = 'SRC';

【讨论】:

以上是关于ORACLE MINUS 关键字的 ANSI SQL 标准的主要内容,如果未能解决你的问题,请参考以下文章

Oracle数据库关键字用法,MERGE、START WITH 、OVER(PARTITION BY) 、MINUS

oracle的minus

oracle的minus怎么使用?

oracle的minus怎么使用?

oracle中minus中有负数

oracle里面的minus,换到sql2000里面是啥?