【问题标题】:Oracle Error-ORA-00933: SQL command not properly endedOracle Error-ORA-00933:SQL 命令未正确结束
【发布时间】:2016-07-09 10:46:13
【问题描述】:

我无法弄清楚为什么我会收到此错误消息....

SELECT student.student, course.coursename, course.coursehours, section.day, section.starttime, course.building, location.room

FROM student, course, section, location, registration

WHERE course.courseid = section.courseid, location.locationid = 
section.locationid, student.studentid = registration.sectionid, 
section.sectionid = registration.sectionid;

Error at line 3:
ORA-00933: SQL command not properly ended

我将数据更新为如下所示:

SELECT student.studentid, 
   course.coursename, 
   course.credithours, 
   section.days, 
   section.starttime, 
   location.building, 
   location.room 
FROM   student 
       INNER JOIN registration 
               ON student.studentid = registration.sectionid 
       INNER JOIN section 
               ON section.sectionid = registration.sectionid 
       INNER JOIN location 
               ON location.locationid = section.locationid 
       INNER JOIN course 
               ON course.courseid = section.courseid; 

但现在它说“没有选择行”?

【问题讨论】:

  • 错误信息是什么?这是 MySQL、SQLite、PostgreSQL 吗?
  • @Prdp 当我发表评论时它没有被标记为 Oracle。
  • 你尝试调试什么?您现在要加入 5 张桌子。加入 2 个表。如果你得到你期望的数据,添加另一个。在每一步建立它的测试。不要编写整个查询然后对其进行测试。如果你这样做,我怀疑你会发现从studentregistration 的连接是错误的。我怀疑studentid 匹配sectionid。我猜你打算加入的registration 中有一个studentid

标签: sql database oracle


【解决方案1】:

当您有多个条件时,您需要使用AND/OR 运算符来应用条件而不是comma。也开始使用INNER JOIN语法

SELECT student.student, 
       course.coursename, 
       course.coursehours, 
       section.day, 
       section.starttime, 
       course.building, 
       location.room 
FROM   student 
       INNER JOIN registration 
               ON student.studentid = registration.sectionid 
       INNER JOIN section 
               ON section.sectionid = registration.sectionid 
       INNER JOIN location 
               ON location.locationid = section.locationid 
       INNER JOIN course 
               ON course.courseid = section.courseid 

【讨论】:

  • 啊,我明白了。谢谢@Prdp!这是较新的语法吗?我被教过上面的 92 版本,并认为我仍然可以以同样的方式做到这一点......
  • 我不再收到错误消息,但它现在返回“未选择行”,您知道这是为什么吗?
  • @ecooper10 - 不看数据就很难判断。确保所有的 Join 条件都是正确的,并且所有的表应该至少有一个匹配的记录
猜你喜欢
  • 2014-04-15
  • 2022-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-09
  • 2010-11-22
相关资源
最近更新 更多