繁体   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