create table a(b number generated always as identity, c number, constraint a_pk primary key (b))
Table created.
insert all into a(c) values (lvl)
into a(c) values (lvl*10)
select level lvl from dual connect by level <= 2
ORA-00001: unique constraint (SQL_ZAEKVOFOCDQFWSOBAFBCJIYGP.A_PK) violated ORA-06512: at "SYS.DBMS_SQL", line 1721More Details: https://docs.oracle.com/error-help/db/ora-00001
drop table a
Table dropped.
create table a(b number, c number, constraint a_pk primary key (b))
Table created.
create sequence a_s
Sequence created.
create trigger a_pk_trg before insert on a for each row
begin
:new.b := a_s.nextval;
end;
Trigger created.
insert all into a(c) values (lvl)
into a(c) values (lvl*10)
select level lvl from dual connect by level <= 2
4 row(s) inserted.
select * from a
B | C | 1 | 1 | 3 | 2 | 2 | 10 | 4 | 20 |
---|
drop table a
Table dropped.
drop sequence a_s
Sequence dropped.
~
Invalid statement
create table a(b number generated always as identity, c number, constraint a_pk primary key (b))
Table created.
insert all into a(c) values (lvl)
into a(c) values (lvl*10)
select level lvl from dual connect by level <= 2
ORA-00001: unique constraint (SQL_ZAEKVOFOCDQFWSOBAFBCJIYGP.A_PK) violated ORA-06512: at "SYS.DBMS_SQL", line 1721More Details: https://docs.oracle.com/error-help/db/ora-00001
drop table a
Table dropped.
create table a(b number, c number, constraint a_pk primary key (b))
Table created.
create sequence a_s
Sequence created.
create trigger a_pk_trg before insert on a for each row
begin
:new.b := a_s.nextval;
end;
Trigger created.
insert all into a(c) values (lvl)
into a(c) values (lvl*10)
select level lvl from dual connect by level <= 2
4 row(s) inserted.
select * from a
B | C | 1 | 1 | 3 | 2 | 2 | 10 | 4 | 20 |
---|
drop table a
Table dropped.
drop sequence a_s
Sequence dropped.