[Solved] Initializing Nested Table ( G-7110)  


0

Hi There.

 

I'm initializing a nested table:

       lst_chars IS TABLE OF VARCHAR2(40 CHAR);

       list_tbl CONSTANT lst_chars := lst_chars  ('FIRST',  'SECOND',  'THIRD' );

 

It compiles and works well, however StyleCOP is raising the Issue : Major G-7110 [Try to use a named notation ...], even if this is not a call to a function or program.

How can I circunvent this warning.

 

Thanks for your help

 

Diego.

 
1

The following code does not report a G-7110 violation:

DECLARE
   TYPE lst_chars IS TABLE OF VARCHAR2(40 CHAR);
   list_tbl CONSTANT lst_chars := lst_chars  ('FIRST',  'SECOND',  'THIRD');
BEGIN
   <<print_it>>
   FOR i IN 1..list_tbl.COUNT LOOP
      sys.dbms_output.put_line(list_tbl(i));
   END LOOP print_it;
END;
/ 

However, PL/SQL Cop does not do a semantic analysis, therefore false positives are possible. You may use the NOSONAR marker to suppress the warning. Here's an example:

DECLARE
   l_something scott.mytype;
   co_a CONSTANT STRING := 'a';
BEGIN
   l_something := scott.mytype(co_a); -- NOSONAR: avoid G-7110 this is not a function call
END;
/

Another option is to disable the guideline check. See "Guideline skip list" in the SQL Developer preferences or the skip option in the command line utility. In SonarQube you may flag issues as false positives and they won't be reported on subsequent analysis.

 

Thank you.

I didn't want to disable the TAG 7110 since that one is very handy.

The NOSONAR tip definitely did the job.

In anycase stylecop reported the issue G-0000, do not use NOSONAR, but I disabled that tag and now my code is pristine.

 

Best regards

Diego.

  
Working

Please Login or Register