Are Oracle PL / SQL arrays indexed from 0 or from 1?

I have in front of me a piece of code like this:

FOR row IN 1..l_RowSet(1).count LOOP l_a_variable := l_RowSet(1)(row); END LOOP; 

l_RowSet - type ApEx - apex_plugin_util.t_column_value_list - is defined as follows:

 type t_column_value_list is table of wwv_flow_global.vc_arr2 index by pls_integer; 

where wwv_flow_global.vc_arr2 is defined as

 type vc_arr2 is table of varchar2(32767) index by binary_integer; 

vc_arr2 returned to my code from the apex_plugin_util.get_data function. Vc_arr2 is indexed by column number, not row.

As far as I can understand this, this means that the data is effectively stored in a 2D array, indexed by column and then by row.

When using the LOOP operator, will it be indexed from scratch or from one? Since it seems to me that I should make this LOOP redundant, that is:

 l_a_variable := l_RowSet(1)(1); 

But I need to know in advance whether to give 0 or 1 as the starting line.

I cannot find a clear answer in Oracle docs (unsurprisingly, the β€œindex” is a fairly widely used term), and browsing through SO does not show anyone else with the same question.

+8
oracle plsql oracle-apex
source share
1 answer

An associative array is not necessarily dense. There may be an element with index 0, there may be an element with index -1, there may be an element with index 1. Or you can have elements at indices 17, 42 and 127. The code you entered implies that the associative array is dense and that the indices begin with one.

In the specific case, the apex_plugin_util.get_data collection should be dense and should start with 1. If the loop does not actually do anything other than what you sent, you can replace it by retrieving the last element of l_RowSet(1) , i.e.

 l_a_variable := l_RowSet(1)(l_RowSet(1).count); 
+8
source share

All Articles