2

我正在尝试将旧式查询转换为 ANSI。为什么顶部查询失败(错误:ORA-00933:SQL 命令未正确结束)但底部版本有效?

SELECT
  JOBS.STARTED_DATE,
  JOB_SCHEDULE_TECHNICIANS.EMPLOYEE_NUMBER,
  JOB_SCHEDULE_TECHNICIANS.HOURS
FROM JOBS 
JOIN JOB_SCHEDULE_TECHNICIANS ON JOB_SCHEDULE_TECHNICIANS.JOB = JOBS.JOB 
WHERE 
  JOBS.STARTED_TIME BETWEEN to_date('2013-05-01', 'YYYY-MM-DD') 
  AND to_date('2013-05-03', 'YYYY-MM-DD')

SELECT
  JOBS.STARTED_DATE,
  JOB_SCHEDULE_TECHNICIANS.EMPLOYEE_NUMBER, 
  JOB_SCHEDULE_TECHNICIANS.HOURS 
FROM JOBS, JOB_SCHEDULE_TECHNICIANS 
WHERE 
  JOBS.STARTED_TIME BETWEEN to_date('2013-05-01', 'YYYY-MM-DD') 
  AND to_date('2013-05-03', 'YYYY-MM-DD')
  AND JOB_SCHEDULE_TECHNICIANS.JOB = JOBS.JOB
4

1 回答 1

2

我认为以上两个 都没有问题Query

正如Mathew Strawbridge评论的那样,我建议使用分号 (;) 。

像这样:

SELECT
  JOBS.STARTED_DATE,
  JOB_SCHEDULE_TECHNICIANS.EMPLOYEE_NUMBER,
  JOB_SCHEDULE_TECHNICIANS.HOURS
FROM JOBS 
JOIN JOB_SCHEDULE_TECHNICIANS ON JOB_SCHEDULE_TECHNICIANS.JOB = JOBS.JOB 
WHERE 
  JOBS.STARTED_TIME BETWEEN to_date('2013-05-01', 'YYYY-MM-DD') 
  AND to_date('2013-05-03', 'YYYY-MM-DD')
; --  <- Here
SELECT
  JOBS.STARTED_DATE,
  JOB_SCHEDULE_TECHNICIANS.EMPLOYEE_NUMBER, 
  JOB_SCHEDULE_TECHNICIANS.HOURS 
FROM JOBS, JOB_SCHEDULE_TECHNICIANS 
WHERE 
  JOBS.STARTED_TIME BETWEEN to_date('2013-05-01', 'YYYY-MM-DD') 
  AND to_date('2013-05-03', 'YYYY-MM-DD')
  AND JOB_SCHEDULE_TECHNICIANS.JOB = JOBS.JOB

于 2013-05-08T19:19:08.753 回答