简体   繁体   English

日期格式问题,ORACLE

[英]Date Format Issue, ORACLE

I am writing this query, to find data between two dates. 我正在编写此查询,以查找两个日期之间的数据。 The time format I have is exactly like the one I am using in the query 我使用的时间格式与查询中使用的时间格式完全相同

    select TO_CHAR(REC_NO),(FIRSTNAME ||' '|| LASTNAME) as NAME,
           LOC_NAME,TO_CHAR(START_TIME,'yyyy/mm/dd/HH:MI:SS'),
           TO_CHAR(END_TIME,'yyyy/mm/dd/HH:MI:SS'),
           TT_NO,CUST_ID,CUST_MOB,MAC_ADDR,EMAIL_ID,s.STATUS 
     from vw_rtb_visit_assn v 
left join vu_issue_status@jiradb s on v.TT_NO = s.TICKETNUMBER  and TT_NO = '123' 
      and v.ASSN_TIME between to_date('Tue Dec 16 00:00:00 PKT 2014','yyyy/mm/dd')
      and to_date('Wed Dec 17 00:00:00 PKT 2014','yyyy/mm/dd')

My query doesn't execute and gives me a format exception. 我的查询没有执行,并给了我格式异常。

your date are not in actual format of that particular character you pass in where condition 您的日期不是您在条件中传递的特定字符的实际格式

to_date('Tue Dec 16 00:00:00 PKT 2014','yyyy/mm/dd')

it should be 它应该是

to_date('Tue Dec 16 00:00:00 PKT 2014','DY MON DD HH24:MI:SS TZD YYYY')

the format of DATE_IN_CHAR and FORMAT in to_date('DATE_IN_CHAR','FORMAT') should match. to_date('DATE_IN_CHAR','FORMAT')中DATE_IN_CHAR和FORMAT的格式应匹配。

kindly try the below 请尝试以下

  and v.ASSN_TIME between to_date('2014/12/16','yyyy/mm/dd')
  and to_date('2014/12/17','yyyy/mm/dd')

Dates do not have formats. 日期没有格式。 Formats are used for parsing strings as dates or generating strings from dates. 格式用于将字符串解析为日期或从日期生成字符串。 You don't have to do any of these, you simply need to specify the interval as a date literal, as described in the documentation , eg: 您无需执行任何这些操作,只需将间隔指定为日期文字,如文档中所述 ,例如:

  and v.ASSN_TIME between DATE '2014-12-16' AND DATE '2014-12-17'

Date literals are actual date values, not strings that have to be parsed using a specific format. 日期文字是实际的日期值,而不是必须使用特定格式解析的字符串。

You can also specify TIMESTAMP literals with 您还可以使用以下命令指定TIMESTAMP文字

TIMESTAMP '1997-01-31 09:26:50.124'

or 要么

TIMESTAMP '1997-01-31 09:26:56.66 +02:00'

for a TIMESTAMP WITH TIMEZONE. 与时区的时间戳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM