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

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

下次还敢
下次还敢Original
2024-05-07 14:54:17613browse

In Oracle, you can use the TO_DATE function to convert a string into date format, the syntax is TO_DATE(string_expression, format_mask). format_mask is used to specify the format of the date and time part in the string. Common format mask characters include: YYYY (year), MM (month), DD (day), HH24 (hour), MI (minute) and SS (second) ). For example, the query to convert "2023-03-21 17:30:15" to a date is: SELECT TO_DATE('2023-03-21 17:30:15', 'YYYY

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

Oracle string to date function

In Oracle, converting a string to date format can be achieved through the TO_DATE function.

## Syntax:

<code class="sql">TO_DATE ( string_expression, format_mask )</code>

Parameters:

  • string_expression: The string to be converted Expression.
  • format_mask: Specify the format of the date and time parts in the string
#Format Mask

The format mask specifies the date and time parts using the following characters:

    YYYY:
  • Year (for example, 2023)
  • MM:
  • month (for example, 03)
  • DD:
  • day (for example, 21)
  • HH24:
  • hour (24-hour format , for example, 17)
  • MI:
  • minutes (for example, 30)
  • SS:
  • seconds (for example, 15)
Example:

Convert the string "2023-03-21 17:30:15" to date:

<code class="sql">SELECT TO_DATE('2023-03-21 17:30:15', 'YYYY-MM-DD HH24:MI:SS') FROM dual;</code>

Result:

<code>2023-03-21 17:30:15.000000</code>

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!

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