You are on page 1of 18

Release Date: August, 2015

Updates:

1
2
3
4
5
6
7
In a real program, the region_id would not be hard-coded in the OPEN statement, but would be entered by
the user.

8
We specify the datatype of the cursor parameter, but not the size. For example: VARCHAR2, not
VARCHAR2(20). Students will see this again later in the course, when we pass parameters to and from
stored subprograms.

When the cursor is opened, the parameter value is passed to the Oracle server, which uses it to decide
which rows to retrieve into the active set of the cursor. This means that you can open and close an explicit
cursor several times in a block, or in different executions of the same block, returning a different active set
on each occasion.

9
10
11
12
The purpose of this code is to fetch and display all employees in the department with the highest
department_id. Note that the maximum department_id is stored in the v_deptid variable and is then
passed into the empcur cursor. Note also that the SELECT MAX(department_id) …. will always return
exactly one row, so an explicit cursor is not needed for this.

13
Parameters are placed inside parentheses following the CURSOR. FOR…END LOOP statements let you
execute a sequence of statements multiple times. The CURSOR will repeatedly use new value(s) that are
passed into the parameter.

14
15
16
17
18

You might also like