Home > Database > Mysql Tutorial > What's the Difference Between `YYYY` and `RRRR` Year Formats in Oracle SQL's `TRUNC` Function?

What's the Difference Between `YYYY` and `RRRR` Year Formats in Oracle SQL's `TRUNC` Function?

Barbara Streisand
Release: 2024-12-25 12:18:37
Original
574 people have browsed it

What's the Difference Between `YYYY` and `RRRR` Year Formats in Oracle SQL's `TRUNC` Function?

Unveiling the Distinction between 'YYYY' and 'RRRR' in Oracle SQL

In Oracle SQL, the formats 'YYYY' and 'RRRR' both appear to produce the same result when used with the trunc() function in the context of year-based truncations. However, a subtle difference exists between the two.

'YYYY': A Static Representation of the Year

The 'YYYY' format represents the year in a four-digit form, regardless of the input. This means that '27-Jul-1987' will always be truncated to '1987' using this format.

'RRRR': Contextual Year Interpretation

The 'RRRR' format, on the other hand, introduces a specific interpretation rule for years given as two digits. Specifically:

  • Years in the range 00 to 49 are assumed to belong to the current century, using the same first two digits as the current year.
  • Years in the range 50 through 99 are assumed to belong to the previous century.

This rule ensures that dates like '27-Jul-1987' are interpreted consistently, regardless of the current century.

The above is the detailed content of What's the Difference Between `YYYY` and `RRRR` Year Formats in Oracle SQL's `TRUNC` Function?. For more information, please follow other related articles on the PHP Chinese website!

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