Since Oracle does not have auto-increment fields similar to SQL Server, if we want to set a unique column similar to ID, we need to create a sequence first with the help of Oracle sequence, then, each time data is inserted, the ID value is updated through the previous trigger, and the sequence number is added with 1.
Since Oracle does not have auto-increment fields similar to SQL Server, if we want to set a unique column similar to ID, we need to create a sequence first with the help of Oracle sequence, then, each time data is inserted, the ID value is updated through the previous trigger, and the sequence number is added with 1.
The related code is as follows:
1. Create sequence:
The Code is as follows:
Create sequence SEQU_DATA_DATAINFO increment by 1 start with 1 nocycle nocache noorder;
2. Create a trigger:
The Code is as follows:
Create or replace TRIGGER TRIG_TEST
Before insert on TABLE1
FOR EACH ROW
DECLARE
TmpVar NUMBER;
BEGIN
TmpVar: = 0;
Select SEQU_PROC_ASSOCIATEINFO.NextVal into tmpVar from dual;
: New. procid: = tmpVar;
EXCEPTION
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END;