DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketGetTotal`(vTicketId INT) RETURNS decimal(10,2) DETERMINISTIC READS SQL DATA BEGIN /** * Calcula el total con IVA de un ticket. * * @param vTicketId Identificador del ticket * @return Total del ticket */ DECLARE vTotal DECIMAL(10,2); DROP TEMPORARY TABLE IF EXISTS tmp.ticket; CREATE TEMPORARY TABLE tmp.ticket ENGINE = MEMORY SELECT vTicketId ticketFk; CALL ticketGetTotal(NULL); SELECT total INTO vTotal FROM tmp.ticketTotal; DROP TEMPORARY TABLE tmp.ticket, tmp.ticketTotal; RETURN vTotal; END$$ DELIMITER ;