Skip to content

G-2610: Never use self-defined weak ref cursor types.

Minor

Changeability, Maintainability, Portability, Reusability

Reason

There is no reason to define your own weak ref cursor types, as they are not different from the built-in sys_refcursor. Introducing your own types just gives you unnecessary maintenance to perform.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
declare
   type local_weak_cursor_type is ref cursor;
   cv_data local_weak_cursor_type;
begin
   if configuration.use_employee then
      open cv_data for
         select e.employee_id,e.first_name,e.last_name
           from employees e;
   else
      open cv_data for
         select e.emp_id,e.name
           from emp e;
   end if;
end;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
declare
   cv_data sys_refcursor;
begin
   if configuration.use_employee then
      open cv_data for
         select e.employee_id,e.first_name,e.last_name
           from employees e;
   else
      open cv_data for
         select e.emp_id,e.name
           from emp e;
   end if;
end;
/