SET TERM ^ ;

CREATE OR ALTER trigger ttbpdv_mfe_b02i for tbpdv_mfe
active before insert or update position 2
AS
DECLARE VARIABLE NAME_GENERATOR VARCHAR(100);
DECLARE VARIABLE CALC BLOB SUB_TYPE 1 SEGMENT SIZE 80;
BEGIN
    IF(NEW.GENERATOR_MFE IS NULL) THEN
    BEGIN
        :NAME_GENERATOR = 'GTBSESSAO_MFE_'||FN_LPAD(NEW.ID, 4, '0');
        EXECUTE STATEMENT 'CREATE GENERATOR ' || :NAME_GENERATOR || '';
        --EXECUTE STATEMENT 'ALTER SEQUENCE ' || :NAME_GENERATOR || ' RESTART WITH 1000 INCREMENT BY 1';
        NEW.GENERATOR_MFE = :NAME_GENERATOR;

    END
END
^

SET TERM ; ^

