Home

Weak REF CURSOR types should not be used

Description

    The rule "Weak REF CURSOR types should not be used" states that weak REF CURSOR types should not be used in PL/SQL code. A weak REF CURSOR type is a type of cursor that is not strongly typed, meaning that it can return any type of data. This can lead to unexpected results and can make code more difficult to debug. It is therefore recommended to use strongly typed REF CURSOR types instead, which are more reliable and easier to debug.

Key Benefits

  • Efficiency: Using Weak REF CURSOR types can reduce the efficiency of a program due to the extra overhead required to process the data.
  • Data Integrity: Weak REF CURSOR types can lead to data integrity issues as the data is not always retrieved in the same order as it is stored.
  • Security: Weak REF CURSOR types can lead to security issues as the data is not always retrieved in the same order as it is stored, making it easier for malicious actors to access sensitive data.

 

Non-compliant Code Example

DECLARE 
	id customers.id%type; 
	name customers.name%type; 
	address customers.address%type; 
	TYPE customers_c IS REF CURSOR;         --Non compliant code (Weak REF CURSOR types is used)
BEGIN 
   OPEN customers_c; 
   FETCH customers_c into id, name; 
      EXIT WHEN customers_c%notfound; 
      dbms_output.put_line(id || ' ' || name || ' ' || address); 
   CLOSE customers_c; 
END;

Compliant Code Example

DECLARE 
	id customers.id%type; 
	name customers.name%type; 
	address customers.address%type; 
	CURSOR customers_c is   IS REF CURSOR RETURN customers%ROWTYPE;            --Compliant code 
		
BEGIN 
   OPEN customers_c; 
   FETCH customers_c into id, name; 
      EXIT WHEN customers_c%notfound; 
      dbms_output.put_line(id || ' ' || name || ' ' || address); 
   CLOSE customers_c; 
END;
Visual Expert 2024
 VEPLSQLRULE36