Tengo un problema con el secuenciamiento en oracle, lo que sucede es que cuando voy creando registros a la tabla que contiene el secuenciamiento el id se genera de manera desordenada.
[URL="https://ibb.co/iCusX9"]https://ibb.co/iCusX9[/URL]
Código de la secuencia
[URL="https://ibb.co/cLtgaU"]https://ibb.co/cLtgaU[/URL]
Código SQL:
Ver original
CREATE SEQUENCE JSENACE_GEADM.AGENDA_ID_SEQ INCREMENT BY 1 MAXVALUE 999999999999999999999999 MINVALUE 1 CACHE 20
Tabla donde se encuentra la secuencia
[URL="https://ibb.co/cLenFU"]https://ibb.co/cLenFU[/URL]
Código SQL:
Ver original
TRIGGER "JSENACE_GEADM".Agenda_Id_TRG BEFORE INSERT ON Agenda FOR EACH ROW DECLARE v_newVal NUMBER(12) := 0; v_incval NUMBER(12) := 0; BEGIN IF INSERTING AND :NEW.Id IS NULL THEN SELECT Agenda_Id_SEQ.NEXTVAL INTO v_newVal FROM DUAL; -- If this is the first time this table have been inserted into (sequence == 1) IF v_newVal = 1 THEN --get the max indentity value from the table SELECT NVL(MAX(Id),0) INTO v_newVal FROM Agenda; v_newVal := v_newVal + 1; --set the sequence to that value LOOP EXIT WHEN v_incval>=v_newVal; SELECT Agenda_Id_SEQ.NEXTVAL INTO v_incval FROM dual; END LOOP; END IF; -- save this to emulate @@identity utils.identity_value := v_newVal; -- assign the value from the sequence to emulate the identity column :NEW.Id := v_newVal; END IF; END;