I have an assignment, and the course materials do not cover how to do this, and a web search has not been help regarding cursors within functions.
The assignment is to return all last names in the database, but change any according to the case statement parameters. And I am required to use a cursor. Here is my code:
create or replace function Convert_New_Name
return sys_refcursor
as
c_results sys_refcursor;
begin
open c_results for
select
case last_name
when 'King' then 'LION'
when 'Ford' then 'CAR'
when 'Miller' then 'BEER'
else last_name
end as new_name
from employees;
return c_results;
end convert_new_name;
I'm having a hard time finding anything pertinent in searches. The database has 20 rows. This code returns all 20 rows, with required changes, but it returns those 20 row 20 times, instead of once.
There was another post on here with almost the same assignment, but when I tried to post on there, it got deleted, and I got told to ask my own question.
select convert_new_name() from employees;