Create a new function named get_topics()
that has no arguments and returns a table with the following columns:
topic_id int
topic_name varchar
created_year int
(the year when a given topic was created)
In the body of this function, define a FOR LOOP
that will loop through the existing topics from the topic
table. Use the RETURN NEXT
command to build up the final table.
The topic_name
should be lowercase, and all spaces in the topic name have to be replaced by an underscore.
You might find the following built-in functions useful:
EXTRACT()
REPLACE()
LOWER()
And here's how to use them in a FOR
loop:
topic_id := curr_rec.id;
topic_name := REPLACE(LOWER(curr_rec.name), ' ', '_');
created_year := EXTRACT(year FROM curr_rec.created_date);