获取错误ORA-00933

时间:2016-03-21 02:01:54

标签: sql database oracle11g

我发现了一些关于此错误的问题,这个问题之前曾被问过,但这些错误并不完全正是我所期待的。 这就是我在这里问的原因。

运行此查询时出现ORA-00933: SQL command not properly ended错误。

select T.course_id from course as T 
where unique (select R.course_id from section as R
              where T.course_id= R.course_id and R.year = 2009);

以下是截图:

enter image description here

现在,这个查询有什么问题?我该如何解决这个错误?

1 个答案:

答案 0 :(得分:2)

问题是as。 Oracle无法识别表别名。但是,我不明白distinct正在做什么;也许你的意思是exists

select T.course_id
from course T 
where exists (select R.course_id
              from section R
              where T.course_id= R.course_id and R.year = 2009
             );

编辑:

如果要验证子查询中的所有课程都是不同的,并且数据库不支持unique(可能是ANSI操作员,但我不确定它是否在其他地方实现):< / p>

select T.course_id
from course T 
where 1 =  (select (case when count(R.course_id) = count(distinct R.course_id) and
                              count(R.courseJ_id) = count(*)
                         then 1 else 0
                    end)
            from section R
            where T.course_id= R.course_id and R.year = 2009
           );
相关问题