oracle oracle10g中如何将字符串日期转换为日期格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8366522/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:44:46  来源:igfitidea点击:

how to convert a string date to date format in oracle10g

oracleoracle10gplsqldeveloper

提问by leelavinodh

My date value is stored as varchar2and the value is 15/August/2009,4:30 PM, how to convert this to a proper date format like DD-MM-YYYY.

我的日期值存储为varchar2,值是15/August/2009,4:30 PM,如何将其转换为正确的日期格式,如DD-MM-YYYY.

回答by Jeffrey Kemp

You can convert a string to a DATE using the TO_DATE function, then reformat the date as another string using TO_CHAR, i.e.:

您可以使用 TO_DATE 函数将字符串转换为 DATE,然后使用 TO_CHAR 将日期重新格式化为另一个字符串,即:

SELECT TO_CHAR(
         TO_DATE('15/August/2009,4:30 PM'
                ,'DD/Month/YYYY,HH:MI AM')
       ,'DD-MM-YYYY')
FROM DUAL;

15-08-2009

For example, if your table name is MYTABLE and the varchar2 column is MYDATESTRING:

例如,如果您的表名是 MYTABLE 而 varchar2 列是 MYDATESTRING:

SELECT TO_CHAR(
         TO_DATE(MYDATESTRING
                ,'DD/Month/YYYY,HH:MI AM')
       ,'DD-MM-YYYY')
FROM MYTABLE;

回答by PenFold

You need to use the TO_DATEfunction.

您需要使用该TO_DATE功能。

SELECT TO_DATE('01/01/2004', 'MM/DD/YYYY') FROM DUAL;