CREATE OR REPLACE FUNCTION GET_NEW_AUTO_ID(di VARCHAR2) RETURN NUMBER
IS
    nextnumber NUMBER(10);
    license varchar(4);
BEGIN
    SELECT DI000001 into license FROM DT401 WHERE DI026548 = 1;
    IF di = '001400' THEN
        SELECT to_number(di008212)+1 INTO nextnumber FROM DT820 WHERE di008199 = '001400' AND DI008198 = license FOR UPDATE OF di008212;
        UPDATE dt820 SET di008212 = lpad(to_char(nextnumber),9,'0') WHERE di008199 = '001400' AND di008198 = license;
        RETURN nextnumber;
    END IF;
    RETURN NULL;
END;