缺少右括号

时间:2014-12-03 16:34:34

标签: oracle11g

我错过了下面Oracle SQL的右括号

SELECT COUNT(*) FROM OAS_HRMS_LEAVE_DETAIL WHERE(((trunc(TO_DATE('12/10/2014','mm  /dd/yyyy')) BETWEEN trunc(LEAVE_FROM_DATE) AND trunc(LEAVE_TO_DATE))OR(trunc(TO_DATE('12/11  /2014','mm/dd/yyyy')) BETWEEN(trunc(LEAVE_FROM_DATE) AND trunc(LEAVE_TO_DATE)))) AND    (EMPLOYEE_NO='US/Z/054' AND APPROVAL_STATUS IN ('Active','Approved')))

3 个答案:

答案 0 :(得分:0)

非常难以阅读......并且不知道你想要做什么条件。

SELECT COUNT(*) 
FROM OAS_HRMS_LEAVE_DETAIL 
WHERE(((trunc(TO_DATE('12/10/2014','mm/dd/yyyy')) 
BETWEEN trunc(LEAVE_FROM_DATE)AND trunc(LEAVE_TO_DATE)) 
OR (trunc(TO_DATE('12/11  /2014','mm/dd/yyyy')) 
BETWEEN(trunc(LEAVE_FROM_DATE) AND trunc(LEAVE_TO_DATE)))//)// <- one extra added here?
AND(EMPLOYEE_NO='US/Z/054' AND APPROVAL_STATUS IN ('Active','Approved')))

答案 1 :(得分:0)

尝试删除第二个 Trunc(leave_from_date)和Trunc(leave_to_date)

周围的括号
SELECT Count(*)
FROM   oas_hrms_leave_detail
WHERE (
(
    (Trunc(To_date('12/10/2014','mm  /dd/yyyy')) BETWEEN Trunc(leave_from_date) AND    Trunc(leave_to_date))
    OR
    (Trunc(To_date('12/11  /2014','mm/dd/yyyy')) BETWEEN Trunc(leave_from_date) AND    Trunc(leave_to_date))
)
    AND(employee_no='US/Z/054' AND    approval_status IN ('Active','Approved'))) 

答案 2 :(得分:0)

看不到任何错过的右括号问题,但你确实有很多括号!我会尽量减少它们的使用 - 你确实需要它们在有AND和OR的地方,而不是无处不在。

这是一个简化版本:

SELECT COUNT(*) FROM OAS_HRMS_LEAVE_DETAIL 
WHERE
 (   DATE '2014-12-10' BETWEEN trunc(LEAVE_FROM_DATE) AND trunc(LEAVE_TO_DATE)
  OR DATE '2014-12-11' BETWEEN trunc(LEAVE_FROM_DATE) AND trunc(LEAVE_TO_DATE)
  )
AND EMPLOYEE_NO='US/Z/054' 
AND APPROVAL_STATUS IN ('Active','Approved')

注意:

  1. 使用日期文字,例如日期'2014-12-10'而不是TO_DATE函数调用
  2. 无需TRUNC()文字日期
  3. 另外,你真的需要截断LEAVE_FROM_DATE和LEAVE_TO_DATE吗?如果这些只是日期(没有时间部分),那么它们应该被验证(例如检查约束),然后你也可以删除那些TRUNC:

    SELECT COUNT(*) FROM OAS_HRMS_LEAVE_DETAIL 
    WHERE
     (   DATE '2014-12-10' BETWEEN LEAVE_FROM_DATE AND LEAVE_TO_DATE
      OR DATE '2014-12-11' BETWEEN LEAVE_FROM_DATE AND LEAVE_TO_DATE
      )
    AND EMPLOYEE_NO='US/Z/054' 
    AND APPROVAL_STATUS IN ('Active','Approved')