在 Oracle 中格式化日期和时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4597979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Formatting Dates and Times in Oracle
提问by trifolius
I'm working with Oracle and I'm using SQL Developer-1.5.4.59.40 but I have a problem. I don't know how use the format for date. I want to use a format: "dd/mm/aaaa hh24:mm" but Oracle doesn't accept it. Tthe error is:
我正在使用 Oracle 并且我正在使用 SQL Developer-1.5.4.59.40,但是我遇到了一个问题。我不知道如何使用日期格式。我想使用一种格式:“dd/mm/aaaa hh24:mm”,但 Oracle 不接受它。错误是:
ORA-01830: La máscara de formato de fecha termina antes de convertir toda la cadena de entrada
ORA-01830: La máscara de formato de fecha termina antes de convertir toda la cadena de entrada
回答by Jens Schauder
try "DD/MM/YYYY HH24:MI"
尝试“DD/MM/YYYY HH24:MI”
some blind text to make the answer long enough
一些盲文使答案足够长
回答by Harrison
to change the date format for all queries (and have it remembered day to day)
更改所有查询的日期格式(并每天记住它)
in SQL Deverloper:
在 SQL 开发者中:
- Goto Tools
- Preferences
- Database
- NLS
- and change Date Format to "DD/MM/YYYY HH24:MI" (as suggested by Jens)
- 转到工具
- 喜好
- 数据库
- 国家统计局
- 并将日期格式更改为“DD/MM/YYYY HH24:MI”(由 Jens 建议)
now to simply do that in a query
现在只需在查询中执行此操作
SELECT
TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI')
FROM DUAL ;
TO_CHAR(SYSDATE,'DD/MM/YYYYHH24:MI')
------------------------------------
04/01/2011 16:08
回答by Nilesh
If some_date
is the column name of date type then you can use the to_char
function to convert to any format.
如果some_date
是日期类型的列名,则可以使用该to_char
函数转换为任何格式。
select to_char(some_date,'dd/mm/yyyy hh24:mi:ss') from ..
回答by juanchoelx
Try:
尝试:
to_date(some_date,'dd/mm/yyyyhh24:mi:ss')
Where some_date
is for example '31/08/2012'.
some_date
例如“31/08/2012”在哪里。