【问题标题】:Getting Error ORA-00933出现错误 ORA-00933
【发布时间】:2016-03-21 02:01:54
【问题描述】:

我发现了一些关于这个错误的问题,之前有人问过这些问题,但这些问题并不完全符合我的要求。 这就是我必须在这里问的原因。

我在运行此查询时收到 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);

截图如下:

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

【问题讨论】:

  • unique 应该做什么?
  • 如果参数子查询不包含重复元组,unique 构造返回值 true。
  • 。 .我没有遇到过这个运营商。你能指出我在文档中的参考吗?

标签: sql database oracle11g


【解决方案1】:

问题是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 运算符,但我不确定它是否在其他地方实现):

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
           );

【讨论】:

  • 感谢您的回答。我很感激帮助。此查询完美运行。但是,如果有另一种解决方案,其中查询包含 unique 构造但没有显示错误,那就太好了。
  • @BlueeandRed 。 . .您可以在第一个版本中尝试unique 而不是exists。让我知道它是否有效。
  • 使用 unique 而不是 exists 得到错误 ORA-00936: missing expression
  • @BlueeandRed 。 . .我不认为它会起作用。 Oracle 不将unique 识别为运算符(尽管它可以用作select 的修饰符)。
猜你喜欢
  • 2010-11-22
  • 2015-08-24
  • 1970-01-01
  • 2019-03-22
  • 1970-01-01
  • 1970-01-01
  • 2019-08-22
  • 2017-03-12
  • 2014-10-23
相关资源
最近更新 更多