0

我的表结构

Name          Null Type         
------------- ---- ------------ 
T_NO               NUMBER       
T_NAME             VARCHAR2(10) 
ENTERING_TIME      TIMESTAMP(6) 
LEAVING_TIME       TIMESTAMP(6) 
TO_DATE            DATE   

插入语句:

insert INTO t3 VALUES
  (
    1,
    'ram',
    TO_date('01:36:51','HH:MI:SSAM'),
    TO_date('11:59:51','HH:MI:SSPM'),
    to_date('23-09-13','dd-mm-yy')
  )

我的问题是:我特别提到 LEAVING_TIMEPM它显示AM. 我不知道为什么它显示出来。

这个选择有没有问题:

select t_no,t_name, TO_CHAR(ENTERING_TIME,'HH12:MI:SSPM'),
TO_CHAR(LEAVING_TIME,'HH12:MI:SSPM'),TO_DATE from t3

结果是:

T_NO|T_NAME|TO_CHAR(ENTERING_TIME,'HH12:MI:SSPM')|TO_CHAR(LEAVING_TIME,'HH12:MI:SSPM')|TO_DATE
1 公羊 09:45:51AM 04:45:51AM 23-SEP-13
1 个 ram 上午 10:05:51 上午 11:00:51 23-SEP-13
1 公羊 01:36:51AM 11:59:51AM 23-SEP-13
4

1 回答 1

1

Your queries are working as intended.

In your query,

TO_date('11:59:51','HH:MI:SSPM')

You have mentioned the Meridian indicator (PM) in the format, but you haven't given the value for it in the date string. So, it is defaulted as AM.

What you need to do is write it this way.

TO_date('11:59:51PM','HH:MI:SSPM').

Note that 'HH:MI:SSPM' is simply a format specifier. It does not indicate whether the time is AM or PM. You can replace PM with AM and still get the same result.

于 2013-09-23T08:27:20.760 回答