Database Programming With PL/SQL 6-1: Practice Activities: Introduction To Explicit Cursors
Database Programming With PL/SQL 6-1: Practice Activities: Introduction To Explicit Cursors
Database Programming With PL/SQL 6-1: Practice Activities: Introduction To Explicit Cursors
Declared by the programmer for queries that return more than one
row
Disables a cursor, releases the context area, and undefines the active
set
Defined automatically by Oracle for all SQL DML statements, and for
SELECT statements that return only one row
Statement that retrieves the current row and advances the cursor to
the next row either until there are no more rows or until a specified
condition is met
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
2
Try It / Solve It
1. In your own words, explain the difference between implicit and explicit cursors.
2. Which SQL statement can use either an explicit or an implicit cursor, as needed?
A. Write a PL/SQL block to declare a cursor called currencies_cur. The cursor will be used to
read and display all rows from the CURRENCIES table. You will need to retrieve
currency_code and currency_name, ordered by ascending currency_name.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
3
C. Add variable declarations and an executable statement to read ONE row through the
currencies_cur cursor into local variables.
D. Add a statement to display the fetched row, and a statement to close the currencies_cur cursor.
E. Run your block to confirm that it works. It should display: AFA Afghani.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
4
F. Your code so far displays only one row. Modify your code so that it fetches and displays all the
rows, using a LOOP and EXIT statement. Test your modified block. It should fetch and display
each row in the CURRENCIES table. If it doesn't, check that your EXIT statement is in the
correct place in the code.
G. Write and test a PL/SQL block to read and display all the rows in the COUNTRIES table for all
countries in region 5 (South America region). For each selected country, display the
country_name, national_holiday_date, and national_holiday_name. Display only those
countries having a national holiday date that is not null. Save your code (you will need it in the
next practice).
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
5
6. Write a PL/SQL block to read and display the names of world regions, with a count of the
number of countries in each region. Include only those regions having at least 10
countries. Order your output by ascending region name.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.