你可以用to_char()
做到这一点,就像这样:
with sample_data as (select 123 id, to_date('05/01/2005', 'mm/dd/yyyy') dt from dual union all
select 123 id, to_date('07/01/2001', 'mm/dd/yyyy') dt from dual union all
select 123 id, to_date('04/01/2003', 'mm/dd/yyyy') dt from dual union all
select 123 id, to_date('02/01/2002', 'mm/dd/yyyy') dt from dual union all
select 123 id, to_date('06/01/2005', 'mm/dd/yyyy') dt from dual union all
select 123 id, to_date('06/01/2004', 'mm/dd/yyyy') dt from dual)
---- end of mimicking a table called sample_data that has your input data in it. See SQL below:
select id,
dt,
TO_CHAR(sd.dt, '"Q"q-yyyy') qtr
from sample_data sd;
ID DT QTR
---------- ---------- -------
123 05/01/2004 Q2-2005
123 07/01/2001 Q3-2001
123 04/01/2003 Q2-2003
123 02/01/2002 Q1-2002
123 06/01/2005 Q2-2005
123 06/01/2004 Q2-2004