1

当我运行以下代码时,

select count_ee_cnum.counts + count_eefaculty.counts + count_cs_cnum.counts + count_cs_faculty.counts
from 
    ( select count(Ex.cnum) as counts
    from enrolled Ex
    where Ex.cnum in (
    select distinct Ex.cnum
    from faculty Fx, faculty Fy, class Cx, class Cy, enrolled Ex, enrolled Ey
    where Fx.dept = 'EE' and Fy.dept = 'CS' and Cx.fid = Fx.fid and Cy.fid = Fy.fid and Ex.cnum = Cx.cnum and Ey.cnum = Cy.cnum)) count_ee_cnum,

    (select count(Fx.dept) as counts
    from faculty Fx
    where Fx.dept = 'EE') count_ee_faculty,

    (select count(Ey.cnum) as counts
    from enrolled Ey
    where Ey.cnum in (
    select distinct Ey.cnum
    from faculty Fx, faculty Fy, class Cx, class Cy, enrolled Ex, enrolled Ey
    where Fx.dept = 'EE' and Fy.dept = 'CS' and Cx.fid = Fx.fid and Cy.fid = Fy.fid and Ex.cnum = Cx.cnum and Ey.cnum = Cy.cnum)) count_cs_cnum,

    (select count(Fy.dept) counts
    from faculty Fy
    where Fy.dept = 'CS') count_cs_faculty;

SQLPLUS 给我一个错误说

where Fy.dept = 'CS') count_cs_faculty
                      *
ERROR at line 3:
ORA-00933: SQL command not properly ended

我已经尝试了很多方法来消除这个错误,但是,它似乎不起作用。

4

2 回答 2

2

纯粹关注您当前遇到的实际错误,这ERROR at line 3有点浪费,因为突出显示的行大约是第 23 行。

SQL*Plus 将空行视为语句的结尾

SQL 语句或脚本中的空行告诉 SQL*Plus 您已完成输入命令,但还不想运行它。

脚本的前 20 行被忽略;它们被视为三个单独的语句,您以空行结束但从不运行。最后三行是第四个独立语句,您确实运行它,因为终止分号。很明显,这种说法是不完整的。

您可以从脚本中删除空行,或者更改 SQL*Plus 处理它们的方式,方法是set sqlblanklines on在该查询之前添加到脚本中。

当然,您需要解决其他人提出的(整个)查询正在做什么的问题,但这是一个单独的主题。

于 2013-09-24T16:59:02.797 回答
0

这是一个奇怪的查询,因为您只是在 select 中使用第一个子查询,而其余的只是无缘无故地放入 from !

我认为问题出在这里:

(select count(Ey.cnum) as counts
from enrolled Ey
where Ey.cnum in (
select distinct Ey.cnum
from faculty Fx, faculty Fy, class Cx, class Cy, enrolled Ex, enrolled Ey
where Fx.dept = 'EE' and Fy.dept = 'CS' and Cx.fid = Fx.fid and Cy.fid = Fy.fid and Ex.cnum = Cx.cnum and Ey.cnum = Cy.cnum)) count_cs_cnum

您在嵌套查询和外部使用 Ey 别名,这会混淆 sql 引擎。

于 2013-09-24T15:40:52.117 回答