sql - 异常加入Oracle
问题描述
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
;
我收到一个错误
答:ORA-00905 用于指示格式错误的语句,其中 Oracle 解析器指示语句缺少关键字。
Oracle 文档在 ora-00905 错误中记录了这一点:
原因:缺少必需的关键字。... 遇到 ORA-00905 时,您必须更正语法,因为缺少关键字。
解决方案
exception join
在 Oracle中没有 a 这样的东西。就问题而言,只有 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
推荐阅读
- java - PMD 工具是否可以选择显示违规计数的差异(代码更改前后)?
- dialogflow-es - webhook 请求超时 dialogflow v2 迁移(webhook 代码:4)?
- .net - 如何使用经典的 VS csproj 定位 .NET Core?
- java - Delphi 10.2 TNetHTTPClient 在其时间之前超时
- regex - 如何在正则表达式中排除非数字字符
- ios - xcode 10.2 中的 Simulator 3d Touch 选项不可用
- node.js - 从节点 js 查询时无法从 AS400 DB2 数据库中获取 *loval 值
- sql - 使用合并时排序
- python - 如何在 django admin 中添加脚本 type="module"
- firebase - Cloud Firestore for Spark 计划中允许的同时连接是什么