Home

Statements should be on separate lines

Description

    The Pl_Sql code rule "Statements should be on separate lines" states that each individual statement within a Pl_Sql code block should be on its own line. This helps to improve readability and makes it easier to debug any errors that may occur. It also helps to make the code more organized and easier to maintain.

Key Benefits

  • Readability: Statements on separate lines can make code easier to read and understand.
  • Debugging: Having statements on separate lines can make debugging easier, as it is easier to identify the source of errors.
  • Maintainability: Having statements on separate lines can make code more maintainable, as it is easier to modify or add new code.

 

Non-compliant Code Example

DECLARE
	NO_DATA_FOUND EXCEPTION;

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT
		LOOP
			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 NO_DATA_FOUND THEN
	Log_Errors ( 'No data found');
  WHEN ERRORS THEN
	Log_Errors ( 'Error Log...' || Chr(10) || DBMS_UTILITY.FORMAT_ERROR_STACK() );   Log_Errors ( 'Error Log...' || Chr(10) || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE() );   DBMS_OUTPUT.PUT_LINE ( '----------' ); --Non compliant code (Statements are in the same line)
    RAISE;
END CUSTOMER_TABLE_ITERATION;

Compliant Code Example

DECLARE
	NO_DATA_FOUND EXCEPTION;

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT
		LOOP
			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 NO_DATA_FOUND THEN
	Log_Errors ( 'No data found');
  WHEN ERRORS THEN
	Log_Errors ( 'Error Log...' || Chr(10) || DBMS_UTILITY.FORMAT_ERROR_STACK() ); --Compliant code (Statements are in the separate line)
    Log_Errors ( 'Error Log...' || Chr(10) || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE() );
    DBMS_OUTPUT.PUT_LINE ( '----------' );
    RAISE;
END CUSTOMER_TABLE_ITERATION;
Visual Expert 2024
 VEPLSQLRULE170