Using CLOSE Statement in Oracle

This article is written about how to use the Oracle/PLSQL CLOSE statement with syntax and examples.

Description

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

Syntax

The syntax to shut a cursor in Oracle/PLSQL the usage of the CLOSE assertion is:

CLOSE cursor_name;

Parameters or Arguments

cursor_name The title of the cursor that you desire to close.

Example

For example, you could shut a cursor known as c1 with the following command:

CLOSE c1;

Below is a characteristic 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;