You are on page 1of 3

www.oracle.

com/academy

Database Programming with PL/SQL


5-1: Introduction to Explicit Cursors Practice
Activities
Vocabulary
Identify the vocabulary word for each definition below:

m
er as
Declared by the programmer for queries that return more than
Explicit
one row

co
eH w
o.
cursor A label for a context area or a pointer to the context area
rs e
ou urc
Disables a cursor, releases the context area, and undefines the
CLOSE
active set
o
aC s

An allocated memory area used to store the data processed by a


Context area
vi y re

SQL statement

Defined automatically by Oracle for all SQL DML statements,


implicit
and for SELECT statements that return only one row
ed d
ar stu

Statement that executes the query associated with the cursor,


open identifies the active set, and positions the cursor pointer to the
first row
sh is

Statement that retrieves the current row and advances the


Th

fetch cursor to the next row either until there are no more rows or until
a specified condition is met

The set of rows returned by a multiple row query in an explicit


Active set
cursor operation

Try It / Solve It

Copyright © 2016, 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.
https://www.coursehero.com/file/31136631/PLSQL-5-1-Practicedocx/
2

1. In your own words, explain the difference between implicit and explicit cursors.

Implicit is created by the database when certain evens happen and explicit is user
define but can hold multiple rows

2. Which SQL statement can use either an explicit or an implicit cursor, as needed?

select

3. List two circumstances in which you would use an explicit cursor.

Multiple row returns and when manually fetching each row

m
er as
co
eH w
o.
4. Identify three guidelines for declaring and using explicit cursors.
rs e
ou urc
Key words suc as open cursor fetch and close
Write with indentation
Declare variables used to fetch with %type.
o
aC s
vi y re
ed d
ar stu

5. 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.
sh is
Th

Copyright © 2016, 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.
https://www.coursehero.com/file/31136631/PLSQL-5-1-Practicedocx/
3

RAN INTO FORMATTING ISSUES PLACED LAST PART OF 4 HERE

DECLARE
CURSOR holiday_cursor IS
SELECT country_name, national_holiday_date, national_holiday_name
FROM countries
WHERE region_id=5;
v_country_name countries.country_name%TYPE ;
v_holiday countries.national_holiday_date%TYPE;
v_name countries.national_holiday_name%TYPE; BEGIN

m
er as
OPEN holiday_cursor ;
LOOP

co
eH w
FETCH holiday_cursor INTO v_country_name, v_holiday, v_name;
EXIT WHEN holiday_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE(v_country_name||'

o.
'||v_holiday||' '||v_name);
END LOOP; rs e
ou urc
CLOSE holiday_cursor;
END
o
aC s
vi y re
ed d
ar stu
sh is
Th

Copyright © 2016, 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.
https://www.coursehero.com/file/31136631/PLSQL-5-1-Practicedocx/

Powered by TCPDF (www.tcpdf.org)

You might also like