Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

group by extract from date bug

hachemi.ZMar 16 2019 — edited Mar 18 2019

I created a table containing  date column , i made a query containing group by extract(year from date) ; but when adding a not null constraint  the result of the same query was wrong !

is this a bug ?

create table cal1 as 
select to_date('20180101','YYYYMMDD') + (level-1) x 
from dual connect by to_date('20180101','YYYYMMDD') +(level-1) <= to_date('20181231','YYYYMMDD')

alter table cal1 add constraint cal01_uk unique (x);

the following statement return "12 " which is correct

select count(*)
from 
(select 
  extract(year from x) y, 
  extract(month from x) m 
from cal1 
group by extract(year from x) ,extract(month from x) 
)

but when define the column as not null the same statement return all the row in the without group

ALTER TABLE cal1 MODIFY (x NOT NULL ENABLE);

select count(*)
from 
(select 
  extract(year from x) y, 
  extract(month from x) m 
from cal1 
group by extract(year from x) ,extract(month from x) 
)

the statements and the results can be found

https://livesql.oracle.com/apex/livesql/s/h31qyktger8yg4g5wrjoc5wft
This post has been answered by Paulzip on Mar 17 2019
Jump to Answer
Comments
Post Details
Added on Mar 16 2019
7 comments
928 views