我在 Oracle 的相关子查询中遇到“缺少关键字”错误

阿扬·米特拉
EXPLAIN SELECT S.ITEMID, X.STATUS
FROM
(select itemid,itemdescription from A WHERE parent_itemid IN(SELECT ITEMID FROM A WHERE itemtype='CT') AND itemtype='SK' AND id='02') S,
(select  s1.itemid from s1,s2 where s1.itemid=s2.itemid and status='RC' )  X
where S.itemid=X.itemid
小脚怪

引起问题的不是相关子查询,而是语法。不仅explain,而且explain plan for

我没有你的桌子,所以我用了斯科特的(正确加入):

SQL> explain plan for select s.dname, x.ename
  2  from (select d.deptno,
  3               d.dname
  4        from dept d
  5        where d.deptno in (select b.deptno
  6                           from dept b
  7                           where b.deptno = 10
  8                          )
  9       ) s join
 10       (select e.deptno,
 11               e.ename
 12        from emp e
 13        where e.deptno = 10
 14       ) x
 15    on s.deptno = x.deptno;

Explained.

SQL>

在你的情况下,假设其他一切都是正确的,

explain plan for select s.itemid, x.status
from (select a.itemid,
             a.itemdescription 
      from a 
      where a.parent_itemid in (select b.itemid 
                                from a b 
                                where b.itemtype = 'CT'
                               ) 
        and a.itemtype = 'SK' 
        and a.id = '02'
     ) s join
     (select s1.itemid 
      from s1 join s2  on s1.itemid = s2.itemid 
      where s1.status = 'RC'         --> which table does STATUS belong to?
     )  x
  on s.itemid = x.itemid;

我还建议您始终使用表别名,因为不清楚什么属于哪个表。例如,status = 'RC'- 没有别名,就不可能知道哪个表有它。如果两者都有,你就会有歧义

最后,编写格式化查询。您发布的混乱难以阅读和理解。大多数现代 GUI 工具都有内置的格式化程序;我建议你使用它。或者,使用在线格式化程序之一。或者,手动格式化。尽量不要做你现在正在做的事情。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

当我在CTE中尝试with-clause的概念时,oracle中缺少关键字错误

缺少关键字错误 - 将子查询与 Oracle 连接

缺少关键字错误oracle

带有 Case 语句缺少关键字错误的 Oracle SQL- 更新查询

Oracle SQL 中 CASE 中的“缺少关键字”

错误:在表中插入多列时缺少关键字-Oracle 11g

Oracle匿名PL / SQL块中缺少关键字错误

无法更正 Oracle 错误 ORA-00905 SQL 中缺少关键字

Oracle Case缺少关键字

Oracle合并命令-缺少关键字

相关子查询,oracle sql

在 oracle 中未找到预期错误的地方的关键字

当我确实有选择关键字时,缺少选择关键字错误

Oracle SQL MERGE 合并到查询 ORA-00905:缺少关键字

Oracle中的“ THE”关键字是什么?

Oracle SQL 相关子查询 - 在某些列中返回计数(*)

Oracle 9i缺少关键字“值”

Oracle ORA-0095:缺少关键字

Oracle:使用 CTE 时缺少 SELECT 关键字

ORA-00908:Oracle SQL中缺少NULL关键字(blob数据类型)

为什么我不断收到此错误消息 ORA-00928:缺少 SELECT 关键字?

Oracle相关子查询,过滤结果

尝试用oracle表中的空间重命名列时出错。错误-SQL错误:ORA- 00946:缺少TO关键字

我收到 ORA-00905:缺少关键字

子查询返回多于1行错误,尽管我使用的是“ IN”关键字

通过Jenkins运行我的Oracle DB查询

我没有发现 Oracle Sql 错误

我在python中遇到关键错误

我有查询,我希望它在 Oracle 中有分页?