Oracle Plsql Close Statement

Oracle / PLSQL: CLOSE Statement

This Oracle tutorial explains how to use the Oracle/PLSQL CLOSE statement with syntax and examples.

Description

The final step of working with cursors is to close the cursor once you have finished using it.

Syntax

The syntax to close a cursor in Oracle/PLSQL using the CLOSE statement is:

CLOSE cursor_name;

Parameters or Arguments

cursor_name

The name of the cursor that you wish to close.

Example

For example, you could close a cursor called c1 with the following command:

CLOSE c1;

Below is a function that demonstrates how to use the CLOSE statement:

CREATE OR REPLACE Function FindCourse
   ( name_in IN varchar2 )
   RETURN number
IS
   cnumber number;

   CURSOR c1
   IS
     SELECT course_number
     FROM courses_tbl
     WHERE course_name = name_in;

BEGIN

   OPEN c1;
   FETCH c1 INTO cnumber;

   if c1%notfound then
      cnumber := 9999;
   end if;

   CLOSE c1;

RETURN cnumber;

END;