My Oracle Support Banner

Wrong Result Using GROUP BY with EXTRACT Function Against DATE (Doc ID 2629968.1)

Last updated on JANUARY 23, 2020

Applies to:

Oracle Database - Standard Edition - Version 12.2.0.1 and later
Information in this document applies to any platform.

Symptoms

After upgrading from 12.1 to 12.2.0.1, wrong results are being returned from query using GROUP BY with EXTRACT function against DATE.
Those duplicated rows are not aggregated.

Testcase
~~~~~~~~~~
drop TABLE <TABLENAME>   purge;

  CREATE TABLE <TABLENAME>   
   ( CALENDAR_NAME CHAR(17),   
     BUSINESS_DATE DATE,   
     UPDATE_TS TIMESTAMP (6) DEFAULT systimestamp,   
     CONSTRAINT PK_<TABLENAME> PRIMARY KEY (BUSINESS_DATE)  
   )
;

insert into <TABLENAME> (business_date)
select sysdate + 10 * rownum
from all_objects where rownum <= 40
/

commit;

select
    extract(year from business_date) , count(*)
from
    <TABLENAME>
group by extract(year from business_date)
order by extract(year from business_date)
/

Wrong results in 12.2.0.1 above environment:

EXTRACT(YEARFROMBUSINESS_DATE)   COUNT(*)
------------------------------ ----------
                          2020          1
                          2020          1
                          2020          1
                          2020          1
... ...
                          2021          1
                          2021          1
                          2021          1
                          2021          1
                          2021          1
                          2021          1

40 rows selected.

Correct results in 12.1 enviroment:

EXTRACT(YEARFROMBUSINESS_DATE)   COUNT(*)
------------------------------ ----------
                          2020         34
                          2021          6

2 rows selected.



Changes

 Upgrade to 12.2 above from 12.1.

Cause

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


In this Document
Symptoms
Changes
Cause
Solution
References


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.