Home

The RELIES_ON clause should not be used

Description

    The RELIES_ON clause should not be used as it can lead to unexpected results and can cause the code to be difficult to maintain. This clause is used to indicate that the execution of a particular statement depends on the successful execution of a previous statement. This can lead to unpredictable results and can cause the code to become difficult to maintain. Additionally, it can also lead to performance issues as the code may not be optimized for the best performance. Therefore, it is best to avoid using the RELIES_ON clause in PL/SQL code.

Key Benefits

  • No Unnecessary Dependencies: The RELIES_ON clause should not be used as it can create unnecessary dependencies between objects, making it difficult to maintain and debug.
  • Flexibility: By avoiding the use of the RELIES_ON clause, developers are able to more easily adjust their code to changing requirements as it is not bound by dependencies.
  • Easier Testing: Without the RELIES_ON clause, it is easier to test code as it is not dependent on other objects.

 

Non-compliant Code Example

CREATE OR REPLACE FUNCTION GetCustomerPhoneNumber (customerId IN INTEGER)
  RETURN NUMBER
  RESULT_CACHE RELIES_ON (CUSTOMERS)            --Non compliant code (The RELIES_ON clause is used)
AS
  phone_number CUSTOMERS.PHONE_NUMBER%TYPE;
BEGIN
  SELECT PHONE_NUMBER
  INTO   phone_number
  FROM   CUSTOMERS
  WHERE  Id = customerId;
  
  DBMS_LOCK.sleep(2);
  
  RETURN phone_number;
END GetCustomerPhoneNumber;

Compliant Code Example

CREATE OR REPLACE FUNCTION GetCustomerPhoneNumber (customerId IN INTEGER)
  RETURN NUMBER --Compliant code
AS
  phone_number CUSTOMERS.PHONE_NUMBER%TYPE;
BEGIN
  SELECT PHONE_NUMBER
  INTO   phone_number
  FROM   CUSTOMERS
  WHERE  Id = customerId;
  
  DBMS_LOCK.sleep(2);
  
  RETURN phone_number;
END GetCustomerPhoneNumber;
Visual Expert 2024
 VEPLSQLRULE187