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

"END;" statements should be labeled

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Add the missing "xxx" label to this statement.
    • Highlighting:
      Hide

      First: the END statement
      Second: the identifier of the matching package, procedure, function name

      Show
      First: the END statement Second: the identifier of the matching package, procedure, function name
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Targeted languages:
      PL/SQL
    • Irrelevant for Languages:
      ABAP, C#, C, C++, Cobol, CSS, Flex, Go, HTML, Java, JavaScript, Objective-C, PHP, PL/I, Python, RPG, Swift, T-SQL, TypeScript, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources

      Description

      Labels are useful to match the begin and end of each PACKAGE, PROCEDURE or FUNCTION, especially when the code is badly indented or too much nested.
      This rule raised an issue when the END statement of a PACKAGE, PROCEDURE or FUNCTION is having no label matching the name of the corresponding "begin" statement.

      Noncompliant Code Example

      CREATE OR REPLACE PACKAGE BODY cust_sal AS  
         
         PROCEDURE find_sal(c_id customers.id%TYPE) IS 
         c_sal customers.salary%TYPE; 
         BEGIN 
            SELECT salary INTO c_sal 
            FROM customers 
            WHERE id = c_id; 
            dbms_output.put_line('Salary: '|| c_sal); 
         END; -- Noncompliant; not a PROCEDURE
      END; -- Noncompliant; not a PACKAGE
      /
      

      Compliant Solution

      CREATE OR REPLACE PACKAGE BODY cust_sal AS  
         
         PROCEDURE find_sal(c_id customers.id%TYPE) IS 
         c_sal customers.salary%TYPE; 
         BEGIN 
            SELECT salary INTO c_sal 
            FROM customers 
            WHERE id = c_id; 
            dbms_output.put_line('Salary: '|| c_sal); 
         END find_sal; -- Compliant; it's matching the name of the PROCEDURE
      END cust_sal; -- Compliant: it's matching the name of the PACKAGE
      /
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              alexandre.gigleux Alexandre Gigleux
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: