Home

Jump statements should not be redundant

Description

    The rule "Jump statements should not be redundant" states that when writing PL/SQL code, unnecessary jump statements should be avoided. Jump statements are used to transfer control from one part of the code to another, and when they are redundant, they can cause confusion and make the code harder to read and understand. Therefore, it is important to ensure that all jump statements used in PL/SQL code are necessary and relevant to the code's purpose.

Key Benefits

  • Reduced complexity: Jump statements should not be redundant to reduce complexity and make code easier to read and understand.
  • Increased speed: By avoiding redundant jump statements, code can run faster, as fewer instructions are needed to be processed.
  • Improved maintainability: By avoiding redundant jump statements, code is more maintainable as it is easier to debug and modify.

 

Non-compliant Code Example

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT  
		LOOP	
			EXIT WHEN CUSTOMER_TABLE(i).Id > 25; 
			IF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			END IF;
			CONTINUE; --Non compliant code (Jump statements is redundant)
		END LOOP;
EXCEPTION
  WHEN ERRORS THEN
	RETURN;
END CUSTOMER_TABLE_ITERATION;

Compliant Code Example

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT  
		LOOP	--Compliant code
			EXIT WHEN CUSTOMER_TABLE(i).Id > 25; 
			IF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			END IF;
		END LOOP;
EXCEPTION
  WHEN ERRORS THEN
	RETURN;
END CUSTOMER_TABLE_ITERATION;
Visual Expert 2024
 VEPLSQLRULE110