簡體   English   中英

在 oracle SQL 中格式化日期

[英]format date in oracle SQL

我試圖學習如何在 oracle pl oracle 中格式化日期,當我在查詢下面運行時返回錯誤

SELECT TO_DATE('01-JAN-00', 'YYYY-DD-MM') FROM dual;

the error message is

ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 -  "a non-numeric character was found where a numeric was expected"
*Cause:    The input data to be converted using a date format model was
           incorrect.  The input data did not contain a number where a number was
           required by the format model.
*Action:   Fix the input data or the date format model to make sure the
           elements match in number and type.  Then retry the operation.

您要么沒有使用正確的格式說明符,要么沒有傳遞正確的字符串。 你要:

SELECT TO_DATE('2000-01-01', 'YYYY-DD-MM') FROM DUAL;

或者:

SELECT TO_DATE('01-JAN-00', 'DD-MON-YY') FROM DUAL;

或者你可以簡單地聲明一個DATE文字:

SELECT DATE'2000-01-01' FROM DUAL;

對於我的場景,我不得不使用 to_char 完美解決格式問題。

SELECT TO_CHAR('01-JAN-00', 'yyyy-DD-MM') FROM dual;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM