I have an associative array like this:
continent_population('Australia') := 30;
continent_population('Antarctica') := 90;
continent_population('UK') := 50;
How do I sort this array after values in PL/SQL? Thanks!
I have an associative array like this:
continent_population('Australia') := 30;
continent_population('Antarctica') := 90;
continent_population('UK') := 50;
How do I sort this array after values in PL/SQL? Thanks!
The accepted answer is outdated. Since Oracle 12c, querying associative arrays using the TABLE operator is possible, as long as the type is declared in a package spec: https://galobalda.wordpress.com/2014/08/02/new-in-oracle-12c-querying-an-associative-array-in-plsql-programs/
You can sort an associative array by values, and you don't have to convert the data: Sorting an index-by table (associative array)
You can't sort an associative array by values, but you have to convert the data to some other data structure and make the sorting there. The easiest way would have been to convert to another associative array where keys and values swap places, but that requires your key values should be unique too.
Below is an example adapted to your case from Sorting PL/SQL Collections. Please check that article for the details.
Prints: