n an application, I intend on truncating and inserting on an Oracle 12c database, but have found this issue with an IDENTITY
column. Even though the INSERT... SELECT
statement works on most SELECT
uses I have tried, when this statement also has a GROUP BY
clause, it fails to work, issuing a "ORA-00979: not a GROUP BY
expression" complaint. Below is some example code:
create table aux ( owner_name varchar2(20), pet varchar2(20) );
insert into aux values ('Scott', 'dog');
insert into aux values ('Mike', 'dog');
insert into aux values ('Mike', 'cat');
insert into aux values ('John', 'turtle');
create table T1 (
id number generated always as identity,
owner_name varchar2(20),
pet_count number );
select owner_name, count(*) as pet_count from aux group by owner_name; -- works just fine
insert into T1 (owner_name, pet_count) select owner_name, count(*) as pet_count from aux group by owner_name; -- doesn't work
The select statement works by itself, but fails as a INSERT ... SELECT statement.
Appreciate the help!