Code Listing 4: A better book_from_list function

CREATE OR REPLACE FUNCTION book_from_list (
   list_in IN book_tabtype,
   title_in IN book.title%TYPE)
RETURN book%ROWTYPE 
IS

   indx PLS_INTEGER;
   retval book%ROWTYPE;
BEGIN
   IF title_in IS NOT NULL
   THEN
      indx := list_in.FIRST;

      LOOP
         EXIT WHEN indx IS NULL; 
         IF list_in(indx).title = title_in
         THEN
            retval := list_in(indx);
         END IF;
         indx := list_in.NEXT (indx);

      END LOOP;
   END IF;
   RETURN retval;
END;