Home > Database > Oracle > What is the function to convert string to date in Oracle?

What is the function to convert string to date in Oracle?

下次还敢
Release: 2024-05-07 14:57:16
Original
952 people have browsed it

The function in Oracle that converts a string to a date is TO_DATE. The syntax is TO_DATE(string, format_mask), where format_mask specifies the format of the date part in the string. Common formats include YYYY (year), MM (month), DD (date), HH (hour), MI (minute), SS (seconds) and FF (milliseconds). If the string does not conform to the specified format, the function returns NULL.

What is the function to convert string to date in Oracle?

Function to convert string to date in Oracle

Function to convert string to date in Oracle is TO_DATE.

Syntax

##TO_DATE(string, format_mask)

Among them:

  • string: The string to be converted
  • format_mask: The mask that specifies the format of the date part in the string

Usage example

The following example converts the string "2023-03-08" to a date:

<code class="sql">SELECT TO_DATE('2023-03-08', 'YYYY-MM-DD') FROM dual;</code>
Copy after login
Output:

<code>08-MAR-23</code>
Copy after login

Mask format

format_mask Mask specifies the format of the date portion of the string. The following are common mask formats:

  • YYYY: year (four digits)
  • YY: year (two digits) )
  • MM: Month (two digits)
  • DD: Date (two digits)
  • HH: Hours (two digits)
  • MI: Minutes (two digits)
  • SS: Seconds (two digits) )
  • FF: milliseconds (three digits)

Note

    If the string does not Conforming to the specified mask format, the
  • TO_DATE function will return NULL.
  • The mask can contain optional symbols such as delimiters and prefixes.

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template