在时间范围

时间:2015-06-19 08:50:13

标签: sql oracle

我想要获取sysdate-1' 00:00'的数据在' 59:59'之间时间范围。我试过了,但是我收到了错误。

这是我的询问..

select id_value, tn, LINE_TYPE_ID, ACCOUNT_TYPE_ID, PORT_ID, CURRENT_STATUS_ID, ERROR_CODE, ERROR_DESC, CRM_APP_CODE
from np_tn_dtls a
  join np_port_req_dtls b on A.NP_TXN_ID=B.NP_TXN_ID
  left join np_subscriber_dtls c on a.NP_TXN_ID=C.NP_TXN_ID
  left join np_subscriber_id_dtls d on D.SUBSCRIBER_ID=C.SUBSCRIBER_ID
where (b.REQUEST_START_TIME between sysdate-1 '00:00:00'
      AND sysdate '23:59:59') and (b.port_type_id != 2);

请建议我。

2 个答案:

答案 0 :(得分:2)

这个表达式错了:

between sysdate-1 '00:00:00'
  AND sysdate '23:59:59'

使用trunc来舍入日期,以便您可以写下:

between trunc(sysdate-1) AND trunc(sysdate)

但是,betweenup to and including,因此为了防止在今天午夜发出请求,您最好这样写:

b.REQUEST_START_TIME >= trunc(sysdate-1) AND 
b.REQUEST_START_TIME < trunc(sysdate)

答案 1 :(得分:1)

sysdate '23:59:59'不是有效的构造

使用

    b.REQUEST_START_TIME >= trunc(sysdate-1)
AND b.REQUEST_START_TIME < trunc(sysdate)