問題描述
誰能幫助我如何在 PL/SQL 中將 2016-07-01 01:12:22 PM
轉換為 2016-07-01 13:12:22
?我使用了以下但沒有運氣.
Can anyone help me how to convert 2016-07-01 01:12:22 PM
to 2016-07-01 13:12:22
in PL/SQL? I used the following but no luck.
SELECT TO_TIMESTAMP ('08-FEB-19 06.41.41.000000 PM', 'DD-Mon-RR HH24:MI:SS.FF')
FROM dual
我預計:08-FEB-19 18.41.41.000000
I expect: 08-FEB-19 18.41.41.000000
我收到以下錯誤:
ORA-01830:日期格式圖片在轉換整個輸入字符串之前結束
ORA-01830: date format picture ends before converting the entire input string
推薦答案
您當前的時間戳沒有任何意義,因為它指定的時間為 18
小時,即下午 6 點,但隨后它也指定了AM
子午線指示器,表示早于中午.因此,您可以從 TO_TIMESTAMP
模式中刪除 AM
:
Your current timestamp makes no sense, because it specifies the time as 18
hours, which is 6pm, but then it also specifies the AM
meridian indicator, which means earlier than noon. So, you may remove the AM
from your TO_TIMESTAMP
pattern:
SELECT TO_TIMESTAMP ('08-FEB-19 18.41.41.000000', 'DD-Mon-RR HH24.MI.SS.FF')
FROM dual;
08-FEB-19 06.41.41.000000000 PM
請注意,Oracle 內部確實沒有 12 或 24 小時格式時間戳之類的東西.相反,如果您想以 24 小時格式查看您的 Oracle 時間戳,您可以使用適當的 24 小時格式掩碼調用 TO_CHAR
之類的操作:
Note that there is really no such thing as 12 or 24 hour format timestamp internally in Oracle. Rather, if you want to view your Oracle timestamp in 24 hour format, you may do something like call TO_CHAR
with an appropriate 24 hour format mask:
SELECT
TO_CHAR(TO_TIMESTAMP ('08-FEB-19 18.41.41.000000', 'DD-Mon-RR HH24.MI.SS.FF'),
'DD-Mon-RR HH24.MI.SS.FF') AS ts
FROM dual;
08-Feb-19 18.41.41.000000000
演示
如果您想轉換帶有 12 小時時間和 AM/PM 組件的時間戳字符串,我們可以嘗試:
If you wanted to convert a timestamp string with 12 hour time and an AM/PM component, we can try:
SELECT
TO_CHAR(
TO_TIMESTAMP ('08-FEB-19 06.41.41.000000 PM', 'DD-Mon-RR HH.MI.SS.FF PM'),
'DD-Mon-RR HH24.MI.SS.FF')
FROM dual;
這篇關于如何將“2016-07-01 01:12:22 PM"轉換為“2016-07-01 13:12:22"小時格式?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!