I have a particular table containing a list of Books along with their name and costs. I would like to write a function that finds and prints the name of the book with lowest cost. I wrote a function and called it , and I don't seem to be getting any errors ( Function compiled and Pl/SQL procedure successfully completed). However I don't see any actual output. Here's my code:
CREATE OR REPLACE FUNCTION min_cost
RETURN VARCHAR2 IS
minCostOfBooks VARCHAR2(50);
BEGIN
SELECT NAME
INTO minCostOfBooks
FROM BOOKS
WHERE cost = ( SELECT MIN(cost) FROM BOOKS);
RETURN minCostOfBooks;
END;
And I call it like this:
DECLARE
d VARCHAR2(50);
BEGIN
d := min_cost();
dbms_output.put_line('Book(s) with lowest cost ' || d);
END;
It's hard to know what the problem is because I don't seem to be seeing any errors.