【问题标题】:Exception join Oracle异常加入Oracle
【发布时间】:2020-07-16 04:34:23
【问题描述】:
              SELECT a.product_name
                   , a.product_price
                   , c.restaurant_id
                   , c.restaurant_name
                   , c.phone_number
                FROM MENU a 
RIGHT EXCEPTION JOIN RESTAURANT c 
                  ON a.restaurant_id=c.restaurant_id 
            ORDER BY a.restaurant_id
                   ;

我遇到了一个错误

Answer: ORA-00905 用于指示格式错误的语句,其中 Oracle 解析器指示语句缺少关键字。

Oracle 文档在 ora-00905 错误中记录了这一点:

原因:缺少必需的关键字。 ... 遇到 ORA-00905 时,您必须更正语法,因为缺少关键字。

【问题讨论】:

  • 您查询的目的是什么?

标签: sql oracle exception join


【解决方案1】:

Oracle 不支持EXCEPTION JOIN。我也不认为它是 ANSI 语法。那一定来自其他数据库。

【讨论】:

    【解决方案2】:

    Oracle 中没有exception join 这样的东西。就问题而言,只有 DB2 支持这种语法。

    如果你想要所有没有餐厅的菜单,我建议not exists

    select m.*
    from menu m
    where not exists (select 1 from restaurant r where r.restaurant_id = m.restaurant_id)
    order by m.restaurant_id
    

    你也可以用反left join来表达:

    select m.*
    from menu m
    left join restaurant r on r.restaurant_id = m.restaurant_id 
    where r.restaurant_id is null
    order by m.restaurant_id    
    

    另一方面,如果您希望所有餐厅都没有菜单,则只需反转查询中的表格即可:

    select r.*
    from restaurant r
    where not exists (select 1 from menu m where r.restaurant_id = m.restaurant_id)
    order by r.restaurant_id
    

    【讨论】:

    • 反左连接说缺少空关键字
    • @Robby:请完全按照提供的方式运行查询。据推测,您在where r.restaurant_id is 之后缺少null
    猜你喜欢
    • 2017-01-03
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    • 2010-12-30
    • 2011-12-12
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    相关资源
    最近更新 更多