分享

Oracle TO_DATE

 昵称62509612 2019-03-03

This tutorial explains how to use Oracle TO_DATE function with basic syntax and examples.

TO_DATE function convert a character string to a date format.

Syntax:

TO_DATE(char[, 'format_model'], [nlsparams])
  • Char : The character that will be converted to a date

  • 'format_model' : format that will be used to convert char to a date. If format_model is not specified, the format is DD-MON-YY. and It can be one or a combination of the following values:

ParameterExplanation
SCC or CCCentury; server prefixes BC date with –
Years in dates YYYY or SYYYYYear; server prefixes BC date with –
YYY or YY or YLast three, two, or one digits of year
Y, YYYYear with comma in this position
IYYY, IYY, IY, IFour-, three-, two-, or one-digit year based on the ISO standard
SYEAR or YEARYear spelled out; server prefixes BC date with –
QQuarter of year
MMMonth: two-digit value
MONTHName of month padded with blanks to length of nine characters
MONName of month, three-letter abbreviation
RMRoman or brown
WW or WWeek of year or month
DDD or DD or DDay of year, month, or week
DAYName of day padded with blanks to a length of nine characters
DYName of day; three-letter abbreviation
JJulian day; the number of days since December 31, 4713 BC
RRRRAccepts a 2-digit year and returns a 4-digit year.
A value between 0-49 will return a 20xx year.
A value between 50-99 will return a 19xx year.
HHHour of day (1-12).
HH12Hour of day (1-12).
HH24Hour of day (0-23).
MIMinute (0-59).
SSSecond (0-59).
SSSSSSeconds past midnight (0-86399).
AM, AM, PM, or PMMeridian indicator
  • Nlsparams : has the same purpose in this function as in the TO_CHAR function for date conversion

Example:

Let's get some examples about Oracle TO_DATE and how to use it:

SELECT to_date ('2019/03/01', 'yyyy/mm/dd')FROM   dual;
Oracle to_date
SELECT TO_DATE('030119', 'MMDDYY')FROM   dual;
Oracle to_date
SELECT TO_DATE('20190301', 'yyyymmdd')FROM   dual;
Oracle to_date
SELECT TO_DATE('2019/03/01 18:00:59', 'YYYY/MM/DD HH24:MI:SS'), TO_DATE('2019/02/05 09:19:59', 'YYYY/MM/DD HH:MI:SS')FROM   dual;
Oracle to_date

Source :  https://www./wiki/oracle-to-date

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多