What I have to do is to print in output several rows from a stored procedure query without using cursors (if there is a way). My database is about a video rental store and what I need to do is show a list of similar movies based on the genre of the given movie. The procedure takes in input the movie name and what I have to print in output a list of movies with the same genre.
The table FILM is made like this:
Genre VARCHAR2(50);
Title VARCHAR2(50);
releaseDate DATE;
duration INT;
I already did it using cursors and it works, but I have to do it without PL/SQL, just using "pure sql".
I guess the right query to do this is the following:
SELECT title,genre FROM FILM WHERE genre = (
SELECT genre FROM FILM WHERE title='Pulp Fiction');
This query is working if I run into the DB, but How can I have the same result using this query from a procedure? I might need to use INTO for the SELECT and then I can't take a list of movies
I noticed that it isn't clear at all and I do apologize for that. I've made a procedure for the Rent of a specific Movie. I first check if the movie requested is available. If it is not, I want to print (via DBMS_OUTPUT.PUT_LINE...) a list of movies of the same genre of the movie selected.
I made this using cursors, but now all I want to do is doing the same without cursors. I write down the code I made for doing this with the cursors:
-- DECLARATION
CURSOR CU IS
SELECT title,genre
FROM FILM;
-- LOOP ..
SELECT genre INTO genre_sugg
FROM FILM
WHERE upper(title) = upper(film); -- film is the input name of the movie
FOR row_sugg IN CU LOOP
IF(row_sugg.genre = genre_sugg AND row_sugg <> film ) THEN
DBMS_OUTPUT.PUT_LINE('Film: ' || row_sugg.title);
END IF;
END LOOP;
dbms_output, as an exercise...)