DELIMITER $$
DROP FUNCTION IF EXISTS obtiene_marca;
CREATE FUNCTION obtiene_marca
(marca$ VARCHAR(200))
RETURNS INT
BEGIN
	DECLARE resultset INT;
	IF NOT EXISTS (SELECT id FROM marcas WHERE descripcion = UPPER(marca$)) THEN
		INSERT INTO marcas(clave, descripcion) VALUES(clave(), UPPER(marca$));
	END IF;
	SET resultset := (SELECT id FROM marcas WHERE descripcion = UPPER(marca$));
	RETURN resultset;
END
$$

DELIMITER $$
DROP FUNCTION IF EXISTS obtiene_color;
CREATE FUNCTION obtiene_color
(color$ VARCHAR(200))
RETURNS INT
BEGIN
	DECLARE resultset INT;
	IF NOT EXISTS (SELECT id FROM colores WHERE descripcion = UPPER(color$)) THEN
		INSERT INTO colores(clave, descripcion) VALUES(clave(), UPPER(color$));
	END IF;
	SET resultset := (SELECT id FROM colores WHERE descripcion = UPPER(color$));
	RETURN resultset;
END
$$
