Home

Columns should be aliased

Description

    The "Columns should be aliased" rule in PL/SQL code states that when selecting multiple columns from a table, each column should be given an alias. This is done to make the code easier to read and understand. By assigning an alias to each column, it is easier to identify which column is being referenced in the code. This also helps to avoid confusion when referencing columns in other parts of the code. Additionally, it is best practice to use meaningful aliases that accurately describe the column.

Key Benefits

  • Improved readability: Aliasing columns makes it easier to read and understand queries, as it provides a more meaningful name for the column.
  • Simplified maintenance: Aliasing columns makes it easier to maintain queries, as the same column can be referred to by different names in different parts of the query.
  • Eliminates ambiguity: Aliasing columns eliminates ambiguity when multiple tables are joined, as it allows the same column to be referred to by different names in different parts of the query.

 

Non-compliant Code Example

SELECT
    NAME ,    --Non compliant code (Columns without aliased)
    ADDRESS ,
    CREDIT_LIMIT
FROM
    CUSTOMERS

Compliant Code Example

SELECT
    NAME as nameCol,    --Compliant code (Columns with aliased)
    ADDRESS as addressCol,
    CREDIT_LIMIT as creditLimitCol
FROM
    CUSTOMERS
Visual Expert 2024
 VEPLSQLRULE160