Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Clarification on Dbms_Plsql_Code_Coverage

sadasivamFeb 11 2020

Hi,

I have the below package to get the code coverage during unit testing(three procedures calling in different scenarios)

Create Or Replace Package MY_CCPKG As

Procedure Proc_C;

PROCEDURE proc_b;

procedure proc_a;

End MY_CCPKG;

Create Or Replace Package Body MY_CCPKG As

Procedure Proc_C As

lv_Avg_OBJECT_ID number;

BEGIN

dbms_output.put_line('calling Proc_C');

For i in 1..5 LOOP

Select Avg(OBJECT_ID)

Into lv_Avg_OBJECT_ID

From All_Objects;

If mod(i,2)=0 THEN

Dbms_output.put_line('i=='||i);

Else

Dbms_output.put_line('lv_Avg_OBJECT_ID=='||lv_Avg_OBJECT_ID);

End if;

End Loop;

End Proc_C;

PROCEDURE proc_b as

lv_date date;

begin

dbms_output.put_line('calling proc_b');

for i in 1..5 LOOP

proc_c;

select sysdate

into lv_date

from dual;

If i in (1,3,5) THEN

return;

Else

dbms_output.put_line(i||'lv_date--'||lv_date);

End if;

End loop;

End proc_b;

procedure proc_a as

lv_count number;

Begin

dbms_output.put_line('calling proc_a');

select count(*)

into lv_count

from all_objects;

for i in 1..5 LOOP

If i=1 Then

proc_b;

ELSif mod(i,2)=0 THEN

Dbms_output.put_line('i/2'||mod(i,2));

ELSif i = 5 THEN

Dbms_output.put_line(i);

Else

Dbms_output.put_line('Else:'||i);

End if;

End Loop;

End proc_a;

End MY_CCPKG;

Executing the code coverage.

declare

L_run Number;

begin

L_Run := Dbms_Plsql_Code_Coverage.Start_Coverage(Run_Comment => 'Start_Code_Coverage Date:'||Sysdate);

MY_CCPKG.proc_a;

Dbms_Plsql_Code_Coverage.Stop_Coverage;

End;

Trying to get the result of the code coverage for above execution(Query)

SELECT LISTAGG(ccb.col, ',') WITHIN GROUP (ORDER BY ccb.col) AS col,

   LISTAGG(ccb.covered, ',') WITHIN GROUP (ORDER BY ccb.col) AS covered,

   LISTAGG(ccb.BLOCK, ',') WITHIN GROUP (ORDER BY ccb.col, ccb.covered) AS Block,

   s.line,

   s.text

FROM dbmspcc_units ccu,

   dbmspcc\_blocks ccb,

               Dba\_source s

WHERE ccu.run_id = 25

And ccu.name = 'MY_CCPKG'

AND ccu.type = 'PACKAGE BODY'

And ccu.run_id = ccb.run_id ( + )

AND ccu.object_id = ccb.object_id ( + )

And s.name = ccu.name

AND s.type = ccu.type

AND s.line = ccb.line(+)

GROUP BY s.line, s.text

ORDER BY 4;

I am getting the below result.I this I dont understand that how the block is calculated and covered is showing the initial line of the calling unit(line 3).Is it covered upto line 9 or only covered line 3?

pastedImage_10.png

Thanks

Comments
Post Details
Added on Feb 11 2020
0 comments
285 views