一些sqlplus错误

时间:2013-09-24 15:28:21

标签: sql oracle

当我运行以下代码时,

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

我已尝试过多种方法来消除此错误,但是,它似乎无效。

2 个答案:

答案 0 :(得分:2)

要完全专注于您当前获得的实际错误,ERROR at line 3有点赠品,因为突出显示的行是关于第23行。

SQL * Plus会对blank line as the end of the statement

进行处理
  

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

您的脚本的前20行被忽略;它们被视为三个单独的陈述(你用空行)但从不运行。最后三行是第四个独立的语句,由于终止分号,你运行它。而这个陈述是不完整的,相当明显。

您可以从脚本中删除空白行,也可以通过在此查询之前向脚本添加set sqlblanklines on来更改SQL * Plus对其的处理方式。

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

答案 1 :(得分:0)

这是一个奇怪的查询,因为你只是在select和rest中使用第一个子查询,只是无缘无故地放入!

我认为问题在于:

(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引擎。