Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3767

SQL statements should not use "CAST(... AS CHAR/VARCHAR)"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Avoid using 'CAST(... AS CHAR/VARCHAR)'
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Covered Languages:
      Cobol
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      CAST(... AS CHAR/VARCHAR) can be a source of incompatibilities between database versions: the behavior of CAST may not be the same depending on the version of the database system. Such incompatibilities can cause unexpected output from applications that CAST decimal data to CHAR or VARCHAR, it's therefore best to avoid using CAST(... AS CHAR/VARCHAR).

      Noncompliant Code Example

        DELETE product
        WHERE CAST(status_code AS CHAR(2)) = '42' -- Noncompliant
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              nicolas.bontoux Nicolas Bontoux (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated: