You can provide auto increment primary with trigger by appling below operations.
Create Table
SQL> CREATE TABLE TESTUSER.TBL_TEST
(id number primary key,
name varchar2(100));
Create Sequence
SQL> CREATE SEQUENCE TESTUSER.SEQ_TEST_ID
START WITH 1
MAXVALUE 999999999
MINVALUE 1
CYCLE
NOCACHE
NOORDER;
Create Trigger For Auto Increment
SQL> CREATE OR REPLACE TRIGGER TESTUSER.TRG_AUTO_INC_TEST_ID
before insert on TESTUSER.TBL_TEST
for each row
begin
if inserting then
if :NEW.”ID” is null then
select TESTUSER.SEQ_TEST_ID.nextval into :NEW.ID from dual;
end if;
end if;
end;
/
Oracle 12c release has primary key auto increment feature with identity type column. You can use like below.
Create Table With Identity Column
SQL> CREATE TABLE TESTUSER.TBL_TEST12C (
id number generated always as identity,
name varchar2(100)
);