Skip to content

New Rule: no SELECT * #46

Closed
Closed
@silviomarghitola

Description

@silviomarghitola

Language Usage / DML & SQL / General
Never use SELECT * in a (sub-)query that selects directly from tables or views

from SonarQube

Columns to be read with a "SELECT" statement should be clearly defined

SELECT * should be avoided because it releases control of the returned columns and could therefore lead to errors and potentially to performance issues.

Noncompliant Code Example

DECLARE
  myvar CHAR;
BEGIN
  SELECT * INTO myvar FROM DUAL;
 END;

Compliant Solution

DECLARE
  myvar CHAR;
BEGIN
  SELECT dummy INTO myvar FROM DUAL;
END;

Exceptions

Wrapper queries using ROWNUM are ignored.

SELECT *
FROM ( SELECT fname, lname, deptId
    FROM employee
    ORDER BY salary
  )
WHERE rownum <= 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions