Question: Using the 'countries' table: a . Write a PL / SQL block to iterate through the 'countries' table for all countries in region 5 (

Using the 'countries' table:
a. Write a PL/SQL block to iterate through the 'countries' table for all countries in region 5(South America). For each country, display the 'country name', 'national holiday date', and 'national holiday name'. Use a record structure to hold the selected columns.
Name the cursor 'yourfirstname countries cur'.
Write your complete PL/SQL code here. This is my code but getting an error
DECLARE
CURSOR yourfirstname_countries_cur IS
SELECT country_name, national_holiday_date, national_holiday_name
FROM countries
WHERE region_id =5;
country_rec yourfirstname_countries_cur%ROWTYPE;
BEGIN
OPEN yourfirstname_countries_cur;
LOOP
FETCH yourfirstname_countries_cur INTO country_rec;
EXIT WHEN yourfirstname_countries_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('Country: '|| country_rec.country_name ||
', National Holiday Date: '|| TO_CHAR(country_rec.national_holiday_date, 'DD-MON-YYYY')||
', National Holiday Name: '|| country_rec.national_holiday_name);
END LOOP;
CLOSE yourfirstname_countries_cur;
END;
b. Modify the code to use a cursor FOR loop, retaining the explicit cursor declaration in the 'DECLARE' section. Test your changes.
Write your complete PL/SQL code here. This is my code but also getting an error.
DECLARE
CURSOR yourfirstname_countries_cur IS
SELECT country_name, national_holiday_date, national_holiday_name
FROM countries
WHERE region_id =5;
BEGIN
FOR country_rec IN yourfirstname_countries_cur LOOP
DBMS_OUTPUT.PUT_LINE('Country: '|| country_rec.country_name ||
', National Holiday Date: '|| TO_CHAR(country_rec.national_holiday_date, 'DD-MON-YYYY')||
', National Holiday Name: '|| country_rec.national_holiday_name);
END LOOP;
END;
Using the 'countries' table: a . Write a PL / SQL

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!