Giter Club home page Giter Club logo

Comments (2)

PhilippSalvisberg avatar PhilippSalvisberg commented on May 26, 2024 1

makes sense.

from plsql-and-sql-coding-guidelines.

PhilippSalvisberg avatar PhilippSalvisberg commented on May 26, 2024

from SonarSource:

Related "IF/ELSIF" statements and "WHEN" clauses in a "CASE" should not have the same condition
Bug

A CASE and a chain of IF/ELSIF statements is evaluated from top to bottom. At most, only one branch will be executed: the first one with a condition that evaluates to true.

Therefore, duplicating a condition automatically leads to dead code. Usually, this is due to a copy/paste error. At best, it's simply dead code and at worst, it's a bug that is likely to induce further bugs as the code is maintained, and obviously it could lead to unexpected behavior.

Noncompliant Code Example

IF param == 1 THEN
  x := 'A';
ELSIF param == 2 THEN
  x := 'B';
ELSIF param == 1 THEN -- Noncompliant, for sure this is a bug
  x := 'C';
END IF;

result := CASE param
   WHEN 1 THEN 'A'
   WHEN 2 THEN 'B'
   WHEN 1 THEN 'C'  -- Noncompliant
   ELSE 'D'
END;

Compliant Solution

IF param == 1 THEN
  result := 'A';
ELSIF param == 2 THEN
  result := 'B';
ELSIF param == 3 THEN
  result := 'C';
END IF;

result := CASE param
   WHEN 1 THEN 'A'
   WHEN 2 THEN 'B'
   WHEN 3 THEN 'C'
   ELSE 'D'
END;

from plsql-and-sql-coding-guidelines.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.