Home

Column names should be used in a SQL ORDER BY clause

Description

    The Pl_Sql code rule that "Column names should be used in a SQL ORDER BY clause" states that when writing a SQL query, the column names should be explicitly specified in the ORDER BY clause. This ensures that the query is written correctly and that the results are ordered in the desired way. This rule also helps to avoid any unexpected behavior when the query is executed.

Key Benefits

  • Organization: Column names can help organize the data in a meaningful way when used in an ORDER BY clause.
  • Efficiency: Using column names in an ORDER BY clause can help reduce the amount of time and resources needed to sort data.
  • Accuracy: Column names can ensure that the data is sorted accurately and consistently.

 

Non-compliant Code Example

SELECT
    NAME,
    ADDRESS,
    CREDIT_LIMIT
FROM
    CUSTOMERS
ORDER BY 10 ASC; --Non compliant code (Order by clause without column names)

Compliant Code Example

SELECT
    NAME,
    ADDRESS,
    CREDIT_LIMIT
FROM
    CUSTOMERS
ORDER BY CREDIT_LIMIT ASC; --Compliant code (Order by clause with column names)
Visual Expert 2024
 VEPLSQLRULE93