Trivadis / plsql-cop-cli

db* CODECOP Command Line
Other
25 stars 1 forks source link

G-5060 bug with 2 queries #47

Open nbroucke opened 2 months ago

nbroucke commented 2 months ago

We get a violation G-5060 : Avoid unhandled exceptions with this code (just showing part of the code) :

image

when we comment the IF statement the violation is no longer there :

image

PhilippSalvisberg commented 2 months ago

@nbroucke thanks for reporting this issue.

I can reproduce it with the following code

create or replace package body department_api is
   function name_by_id(in_id in departments.department_id%type)
      return departments.department_name%type is
      co_id             constant departments.department_id%type := in_id;
      l_department_name departments.department_name%type;
   begin
      if true then
         select department_name
           into l_department_name
           from departments
          where department_id = co_id;

         select department_name
           into l_department_name
           from departments
          where department_id = co_id;
      end if;
      return l_department_name;

   exception
      when no_data_found then
         return null;
      when too_many_rows then
         raise;
   end name_by_id;
end department_api;
/

It's related to the if statement. Without the if no G-5060 is reported.