I want to make happen the same that happens when I do the following
CREATE TABLE "TEST1"
(
"ID" NUMBER(10,0) GENERATED ALWAYS AS IDENTITY,
"APPCODE" VARCHAR2(1)
);
Table TEST1 created.
INSERT INTO TEST1 (ID, APPCODE) VALUES (1,'A');
Error starting at line : 6 in command -
INSERT INTO TEST1 (ID, APPCODE) VALUES (1,'A')
Error at Command Line : 50 Column : 1
Error report -
SQL Error: ORA-32795: cannot insert into a generated always identity column
INSERT INTO TEST (APPCODE) VALUES ('A');
1 row inserted.
but I want to use named sequences, created by me. I want the same behavior as when using the "ALWAYS" keyword (as in "GENERATED ALWAYS AS IDENTITY") and at the same time use my own named sequences, but I don't know how.
With named sequences, it seems to be impossible to avoid that an INSERT uses the ID COLUMN on the insert. But maybe there is a way? This is the question I'm asking. Below I create a named sequence and show the difference (I can't figure out how to prevent the ID column to be allowed on the insert).
CREATE SEQUENCE SEQ_TEST2 START WITH 1 INCREMENT BY 1 MINVALUE 1 NOMAXVALUE;
Sequence SEQ_TEST2 created.
INSERT INTO TEST2 (APPCODE) VALUES ('A'); /* This is ok */
1 row inserted.
INSERT INTO TEST2 (ID,APPCODE) VALUES (1928,'A'); /* This is NOT ok */
1 row inserted.
The second insert above is what I want to prevent from happening, it shouldn't be possible to insert on the ID column. I don't care how to prevent it to happen, doesn't have to be the same way that the "ALWAYS" keyword on the TEST1 table works, but I would like to prevent it from happening. Anyone knows please how to to it?