在一個專欄中,我有日期 -01-02-2022, 01-03-2022
我怎樣才能得到以下格式
ABS_DATE Quarter Month
01-02-2022 Q1 2022 02/2022
30-03-2021 Q1 2021 03/2021
29-12-2020 Q4 2020 12/2020
uj5u.com熱心網友回復:
您可以使用該to_char()功能將日期轉換為您需要的任何格式,包括季度:
to_char(abs_date, 'DD-MM-YYYY') as abs_date
to_char(abs_date, '"Q"Q YYYY') as quarter
to_char(abs_date, 'MM/YYYY') as month
參考"Q"的是字符文字,不要與未參考的元素混淆,Q后者是“一年中的季度”的元素。
使用 CTE 獲取樣本資料的演示:
with your_table (abs_date) as (
select date '2022-02-01' from dual
union all
select date '2021-03-30' from dual
union all
select date '2020-12-29' from dual
)
select abs_date as raw_date,
to_char(abs_date, 'DD-MM-YYYY') as abs_date,
to_char(abs_date, '"Q"Q YYYY') as quarter,
to_char(abs_date, 'MM/YYYY') as month
from your_table
| RAW_DATE | ABS_DATE | 四分之一 | 月 |
|---|---|---|---|
| 01-FEB-22 | 01-02-2022 | 2022 年第一季度 | 02/2022 |
| 21 年 3 月 30 日 | 30-03-2021 | 2021 年第一季度 | 03/2021 |
| 20 年 12 月 29 日 | 29-12-2020 | 2020 年第四季度 | 12/2020 |
db<>小提琴
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478834.html
