SET TERM ^ ;

CREATE OR ALTER trigger ttbcategoria_laclofit_b01iu for tbcategoria_laclofit
active before insert or update position 2
AS
declare variable ID_ECOMMERCE INTEGER;
begin

    IF(NEW.ID_ECOMMERCE = 0) THEN
    BEGIN
        NEW.ID_ECOMMERCE = NEW.ID;
    END

    FOR
        SELECT
            T.ID_ECOMMERCE
        FROM TBCATEGORIA_LACLOFIT T
        WHERE T.ID_ECOMMERCE = NEW.ID_ECOMMERCE
        AND T.ID <> NEW.ID
    INTO
        :ID_ECOMMERCE
    DO
    BEGIN
        IF(NEW.ID_ECOMMERCE = :ID_ECOMMERCE) THEN
        BEGIN
            EXCEPTION "..." 'ID DO E-COMMERCE JÁ EXISTENTE, OPERAÇÃO CANCELADA';
        END
    END
end
^

SET TERM ; ^

