Home  >  Article  >  Database  >  What is the usage of to char conversion in oracle

What is the usage of to char conversion in oracle

WBOY
WBOYOriginal
2022-01-26 15:29:324598browse

In Oracle, the "to_char()" function is used to convert dates into character types in a certain format. It is often used in conjunction with select statements. The syntax is "select to_char(date,"conversion format") time from dual;".

What is the usage of to char conversion in oracle

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

What is the usage of to char conversion in oracle

The two conversion functions that are most closely related to date operations in daily work: to_date(), to_char()

many A date format:

  • YYYY: the year represented by four digits

  • YYY, YY, Y: the last three, two or two digits of the year One digit, the default is the current century

  • MM: Month number from 01 to 12

  • MONTH: Nine-character month, right Fill in with spaces

  • MON: three-character month abbreviation

  • ## WW: week of the year

  • D: The day of the week

  • DD: The day of the month

  • DDD: The day of the year Day

  • DAY: The full name of the day represented by nine characters, padded with spaces on the right

  • HH, HH12: Day of the day The hour, in hexadecimal notation

  • HH24: The hour in a day, the value is 00~23

  • MI: Minutes of an hour

  • SS: Seconds of a minute

  • SSSS: Number of seconds elapsed since midnight

1.to_date(): It converts character type into date type according to a certain format

Specific usage: to_date(''2004-11-27 '',''yyyy-mm-dd''), the former is a string, and the latter is a converted date format

Note that the two before and after must correspond to one.

For example: to_date(''2004-11-27 13:34:43'', ''yyyy-mm-dd hh24:mi:ss'') will get the specific time

SQL>select to_date('2003-10-17 21:15:37','yyyy-mm-dd hh24:mi:ss') from dual

2.to_char(): The date is converted into a character type according to a certain format

SQL> select to_char(sysdate,''yyyy-mm-dd hh24:mi:ss'') time from dual;

  TIME
  -------------------
  2004-10-08 15:22:58

That is, convert the current time into character type according to yyyy-mm-dd hh24:mi:ss format

What is the usage of to char conversion in oracle

Recommended tutorial: "

Oracle Video Tutorial"

The above is the detailed content of What is the usage of to char conversion 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