Difficulties in trigger creation in MYSQL

0

You are giving the error # 1064, I do not know what I do, please help me ...

CREATE TRIGGER comissao
    ON tb_Pedido
    FOR INSERT, UPDATE, DELETE
    AS
    BEGIN
        DECLARE
        v_codFuncionario INT DEFAULT NULL;
        DECLARE v_dataPedido DATETIME(3) DEFAULT NULL;
        DECLARE v_valorComissao DECIMAL(15,4) DEFAULT NULL

        IF(SELECT COUNT(*) FROM INSERTED) = 1 AND (SELECT COUNT(*) FROM DELETED) = 1 
            THEN
                SET v_codFuncionario = (SELECT codFuncionario FROM DELETED);
                SET v_dataPedido = (SELECT dataPedido FROM DELETED);
                DELETE FROM tb_Comissao WHERE dataPedido = v_dataPedido AND codFuncionario = v_codFuncionario;

                SET v_codFuncionario = (SELECT codFuncionario FROM INSERTED);
                SET v_dataPedido = (SELECT dataPedido FROM INSERTED);
                SET v_valorComissao = (SELECT totalPedido FROM INSERTED); * 0.05
                INSERT INTO tb_Comissao (codFuncionario, dataPedido, valorComissao) VALUES (v_codFuncionario, v_dataPedido, v_valorComissao);
        ELSE
                IF(SELECT COUNT(*) FROM INSERTED) = 1
                    THEN
                        SET v_codFuncionario = (SELECT codFuncionario FROM INSERTED);
                        SET v_dataPedido = (SELECT dataPedido FROM INSERTED);
                        SET v_valorComissao = (SELECT totalPedido FROM INSERTED); * 0.05
                        INSERT INTO tb_Comissao (codFuncionario, dataPedido, valorComissao) VALUES (v_codFuncionario, v_dataPedido, v_valorComissao);
                ELSE
                        SET v_dataPedido = (SELECT dataPedido FROM DELETED);
                        DELETE FROM tb_comissao WHERE dataPedido = v_dataPedido AND codFuncionario = v_codFuncionario;
                    END IF;
            END IF;
    END
    
asked by anonymous 06.06.2018 / 01:15

0 answers