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!

Collections - How to COUNT the number of Elements of Multidimensional Collection

J-Ricardo-GJun 2 2017 — edited Jun 19 2017

Der All

I'm coding PL/SQL in Oracle DB 11g and I'm using multidimensional collections.  After populating a variable v_freedays which is a two-dimension type I need to know the number of elements of that.    If I use the method COUNT in the form v_freedays.COUNT  it returns only the number of elements of the first dimension.

The data types involved in my code are :

CURSOR Get_Days_of_Project  IS

                SELECT  proj_name, strt_date, end_date, total_months, total_freedays,

                FROM Tproject ;

              

T_Days     IS TABLE OF   Get_Days_of_Project%ROWTYPE  INDEX BY PLS_INTEGER;

T_Matrix   IS TABLE  OF  T_Days                                            INDEX BY PLS_INTEGER;

v_Days                   T_Days ;

v_freedays             T_Matrix;

BEGIN

           OPEN  Get_Days_of_Project;

           FETCH  Get_Days_of_Project BULK COLLECT INTO v_Days

           FOR idxmonth IN 1..100                            -- FIRST DIMENSON will have 100 elements months and its corresponding freedays in each month

           LOOP

                     FOR idxdays  IN 1..V_days.Count         -- SECOND DIMENSION  will have 45 elements corresponding to the lines returned by the cursor

                     LOOP

                                v_freedays(idxmonth)(idxdays).totalfreedays := v_days.totalfreedays;

                     END LOOP;

          END LOOP;

         /* Althoug this code could not make any sense  , the point here is that , at the end,  v_matrix is correctly populated and it works */

        /* The issue now is how to get the total number of elements of this matrix . 100 * 45 = 4500  */

       DBMS_OUTPUT.PUT_LINE('Elements of  Matrix  v_matrix  : '|| v_freedays.count);

END;

Returned :

Elements of  Matrix  v_matrix : 100

I tried  v_freedays() ().count  , but I got the compilation error :

  • PLS-00355: use of pl/sql table not allowed in this context

Does anyone knows how to get the total number of elements of a multidimensional collection ?

Preferable, is it posible to know the number of elements of each dimension ?

I appreciate your help !  Thks !

Ricardo.

This post has been answered by BrendanP on Jun 3 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 17 2017
Added on Jun 2 2017
7 comments
4,132 views