Home

INSERT statements should explicitly list the columns to be set

Description

    The rule "INSERT statements should explicitly list the columns to be set" states that when using an INSERT statement in PL/SQL, the columns that will be set should be explicitly listed. This helps to ensure that the data is being inserted into the correct columns and that the data is valid for the column type. It also helps to avoid any potential errors that may occur when inserting data into the wrong column. Additionally, explicitly listing the columns to be set can help to improve the readability and maintainability of the code.

Key Benefits

  • Explicit Columns: INSERT statements should explicitly list the columns to be set, providing greater control and accuracy.
  • Data Integrity: This rule helps ensure data integrity by ensuring that the correct data is inserted into the right columns.
  • Ease of Maintenance: Explicitly listing the columns makes it easier to maintain the code and modify it when needed.

 

Non-compliant Code Example

BEGIN
	INSERT INTO	EMPLOYEE  --Non compliant code (Insert statements does not explicitly list the columns need to be set)
	VALUES (3,'Demo','Test','52 AAGMAN BUNGALOWS');
END;

Compliant Code Example

BEGIN
	INSERT INTO	EMPLOYEE(EMP_ID,FIRSTNAME,LASTNAME,ADDRESS)  --Compliant code (Insert statements explicitly list the columns need to be set)
	VALUES (3,'Demo','Test','52 AAGMAN BUNGALOWS');
END;
Visual Expert 2024
 VEPLSQLRULE142