

DELIMITER //

CREATE PROCEDURE obtenerRepartoPeliculasPorActor(IN p_patron_nombre_actor VARCHAR(100))
BEGIN
    SELECT 
        a.nombre AS nombre_actor,
        a.id_pais AS id_pais_actor,
        p.titulo AS titulo_pelicula,
        p.id_pais AS id_pais_pelicula,
        d.nombre AS nombre_director,
        d.id_pais AS id_pais_director,
        d.fecha_nacimiento AS fecha_nacimiento_director
    FROM reparto r
    JOIN actor a ON r.id_actor = a.identificador
    JOIN pelicula p ON p.identificador = r.id_pelicula
    JOIN director d ON p.id_director = d.identificador
    WHERE p.identificador IN (
        SELECT re.id_pelicula
        FROM reparto re
        JOIN actor ac ON re.id_actor = ac.identificador
        JOIN pelicula pe ON re.id_pelicula = pe.identificador
        WHERE ac.nombre LIKE p_patron_nombre_actor
    );
END;
//

CREATE FUNCTION obtenerNumeroActoresPelicula(p_id_pelicula INT)
RETURNS INT
DETERMINISTIC
READS SQL DATA
BEGIN
    DECLARE total_actores_pelicula INT;

    SELECT COUNT(*) INTO total_actores_pelicula
    FROM reparto
    WHERE id_pelicula = p_id_pelicula;

    RETURN total_actores_pelicula;
END;
//

DELIMITER ;

