我得到了一个“答案”;缺少关键字";Oracle中的关联子查询出错

我得到了一个“答案”;缺少关键字";Oracle中的关联子查询出错,oracle,Oracle,的正确语法为: 此外,在第二个子查询中,您必须选择列status,因为您希望在外部选择中选择该列: EXPLAIN PLAN FOR SELECT... 另外,status应该由表名限定,以避免任何歧义。产生问题的不是相关子查询,而是语法。不仅仅是解释,而是解释的计划 我没有您的表格,所以我使用了Scott的(正确连接): 在你的情况下,假设其他一切都是正确的 SQL> explain plan for select s.dname, x.ename 2 from (select

的正确语法为:

此外,在第二个子查询中,您必须选择列
status
,因为您希望在外部
选择
中选择该列:

EXPLAIN PLAN FOR
SELECT...
另外,
status
应该由表名限定,以避免任何歧义。

产生问题的不是相关子查询,而是语法。不仅仅是
解释
,而是
解释
的计划

我没有您的表格,所以我使用了Scott的(正确连接):


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

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


最后,编写格式化查询。你贴的乱七八糟的东西很难阅读和理解。大多数现代GUI工具都有内置的格式化程序;我建议你用它。或者,使用一个联机格式化程序。或者,手动设置其格式。尽量不要做现在正在做的事情。

查询中没有相关子查询。提问并提供一个,至少是表的
CREATE
语句。您应该考虑切换到显式<代码>连接< /代码>语法,并用表别名限定所有列。您不会从X’子查询返回X.STATE。
EXPLAIN PLAN FOR
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, status from s1,s2 where s1.itemid=s2.itemid and status='RC' )  X
where S.itemid=X.itemid
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;