Skip to Main Content
  • Questions
  • LAST and COUNT values after VARRAY trimming?

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Michal.

Asked: November 09, 2016 - 7:06 pm UTC

Last updated: September 29, 2021 - 6:18 pm UTC

Version: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

Viewed 1000+ times

You Asked

I would like to ask about the values of LAST and COUNT of the varray after operation TRIM.
In the documentation is written, that " For varrays, COUNT always equals LAST." [ https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/collection_method.htm]

However, when I trim the varray, the values are not the same, value of LAST is incorrect, in my opinion.
What happened? How to solve it?

declare
type t_pole is varray(40) of integer;
pole t_pole;
begin
pole:=t_pole(10,20,30,40,50,60,70,80,90,100,
110,120,130,140,150,160,170,180,190,200,
210,220,230,240,250,260,270,280,290,
300,310,320,330,340,350);
dbms_output.put_line('LIMIT '||' '||pole.limit);
dbms_output.put_line('last '||' '||pole.last);
dbms_output.put_line('count '||' '||pole.count);
dbms_output.put_line('***trim 10 ** ');
pole.trim(11);
dbms_output.put_line('LIMIT '||' '||pole.limit);
dbms_output.put_line('last '||' '||pole.last);
dbms_output.put_line('count '||' '||pole.count);
end;
/


with LiveSQL Test Case:

and Chris said...

Thanks for using LiveSQL!

This appears to be a bug. I've raised it internally.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, September 29, 2021 - 4:35 pm UTC

5 years have passed. Was the problem solved?
Chris Saxon
September 29, 2021 - 6:18 pm UTC

I still see the issue in 21c.

When you spot bugs like this it's always worth you raising them with support. The more customers that log an issue, the higher priority fixing it is!

More to Explore

DBMS_OUTPUT

More on PL/SQL routine DBMS_OUTPUT here