Home  >  Article  >  Database  >  How to convert string to date in oracle

How to convert string to date in oracle

青灯夜游
青灯夜游Original
2022-01-25 18:15:2467932browse

In Oracle, you can use the to_date() function to convert a string into a date. This function can format the string according to the specified format and convert it into a time type result. The syntax "to_date("The characters to be converted String","conversion format")".

How to convert string to date in oracle

The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.

In Oracle, you can use the to_date() function to convert a string into a date.

to_date(x[,f])The function can format the string x according to the format f and convert it into a time type result.

Specific syntax:

to_date("要转换的字符串","转换的格式")

Note: The format of the two parameters must match, otherwise an error will be reported.

Conversion format:

  • Represents year: y Represents the last digit of the year yy Represents the last 2 digits of the year yyy Represents the last 3 digits of the year yyyy Use 4 The number of digits represents the year

  • represents the month: mm represents the month with 2 digits; mon represents the month in abbreviated form such as November or nov; month represents the full name such as November or November

  • means day: dd means the day of the month; ddd means the day of the year; dy is the abbreviation of the day of the week, such as Friday or fri; write the day of the week in full

  • For example, Friday or friday.

  • means hour: hh 2 digits means hour in hexadecimal; hh24 2 digits means hour 24 hours

  • means minute: mi 2 digits represents the minute

  • represents the second: ss 2 digits represents the second in hexadecimal

  • represents the quarter: q One ​​digit The number represents the quarter (1-4)

  • In addition, ww is used to represent the week of the year and w is used to represent the week of the month.

    Time range under 24-hour format: 00:00:00-23:59:59

    Time range under 12-hour format: 1:00:00-12:59:59

Example:

select to_date('2022-01-13','yyyy-mm-dd') from dual;

Output result:

2022/01/13

Recommended tutorial: "Oracle Tutorial"

The above is the detailed content of How to convert string to date in oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn