There are two links http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#LNPLS99981 and
Purpose of using different types of PL/SQL collections in Oracle
by referring above two links i have two doubt
1.Which one is correct nested table?
2.If the oracle doc is correct what is the difference between nested table and associative array?
Here is another difference which is not that commonly known. You can compare two nested tables with
=
or<>
but associative array you cannot.When you work with nested tables you can also use Multiset Operators, Multiset Conditions and
SET
which are not available for associative arrays.A nested table is just an array of n elements.
A nested table must be initialized as shown. It has zero elements at first. To add elements we use EXTEND. This nested table has 10 elements. They are indexed 1 to 10. Element 1 has the value 100. The others have value null. An access to a non-existent element, say the 11th element, raises an error.
An associative array on the other hand is an array of name/value pairs. Let's use numbers (pls_integer typically) for the naming:
An associative array needs no initialization. It is empty and gets populated. Here we associate the element called 1 with the value 100 and the element with the name 11 with the value 1000. So there are two elements in the array. We get a no data found exception when we try to access a name that is not in the array.
We can also use strings for the names:
You can use both collections to get table data, but you use them differently. The nested table has a count and you can just loop from 1 to count to access its elements:
The associative array however must be read from whatever happens to be the first index to the next and next and next using FIRST and NEXT.
The "names" happen to be 1, 2, 3, etc. here (given thus by the bulk collection) and you could access v_my_associative_array(1) for instance. Later in your program, however, after some possible delete operations in the array, there may be gaps, so you don't know whether an element named 1 exists and whether the element before element 4 happens to be element 3. As with bulk collect the "names" for the elements have no meaning you would not really use them, but go instead through the chain as shown.