Let us say that a person has 2 houses.So it means he has two residential addresses. We can store these addresses into an Associative Array. Let us see how
First we need to create an Associative Array Type as under. Please note that the Existing type can only be BINARY_INTERGER or VARCHAR.
Declare Type Resedential_Address_Type IS TABLE OF VARCHAR(20) INDEX BY VARCHAR(20);
Resedential_Addresses Resedential_Address_Type;
Then assign the value
Declare Type Resedential_Address_Type IS TABLE OF VARCHAR(20) INDEX BY VARCHAR(20);
Resedential_Addresses Resedential_Address_Type;
Begin
Resedential_Addresses(1) := '407 St John Street London EC1V 4AD';
Resedential_Addresses(2) := 'Street Address, 64 Newman Street. City, London';
End;
We can access the values as under
SQL> Set ServerOutput On;
SQL> Declare
2 Type Resedential_Address_Type IS TABLE OF VARCHAR(20) INDEX BY VARCHAR(20);
3 Resedential_Addresses Resedential_Address_Type;
4 Begin
5 Resedential_Addresses(1) := '407 St John Street London EC1V 4AD';
6 Resedential_Addresses(2) := 'Street Address, 64 Newman Street. City, London';
7 DBMS_OUTPUT.PUT_LINE('First Value is: ' || Resedential_Addresses(1));
8 DBMS_OUTPUT.PUT_LINE('Second Value is: ' || Resedential_Addresses(2));
9 End;
10 /
First Value is: 407 St John Street London EC1V 4AD
Second Value is: Street Address, 64 Newman Street. City, London
PL/SQL procedure successfully completed.