declare
type driver_info is record (
full_name varchar2(255 char)
, constructor varchar2(255 char)
, age pls_integer
);
type driver_tab is table of driver_info index by varchar2(255);
l_driver_info driver_info;
l_driver_tab driver_tab;
l_key varchar2(255);
begin
l_driver_info.full_name := 'Max Verstappen';
l_driver_info.constructor := 'Red Bull';
l_driver_info.age := 24;
l_driver_tab('verstappen') := l_driver_info;
l_driver_info.full_name := 'Carlos Sainz';
l_driver_info.constructor := 'Ferrari';
l_driver_info.age := 27;
l_driver_tab('sainz') := l_driver_info;
if l_driver_tab.exists('verstappen') then
l_driver_info := l_driver_tab('verstappen');
dbms_output.put_line(l_driver_info.full_name || ' is ' || l_driver_info.age || ' years old and is a ' || l_driver_info.constructor || ' driver.');
end if;
if not l_driver_tab.exists('prost') then
dbms_output.put_line('prost is not present in Associative Array');
end if;
l_driver_tab.delete('sainz');
dbms_output.put_line( l_driver_tab.count || ' driver(s) left in the Associative Array.');
-- short syntax
l_driver_info := driver_info(full_name=>'Nico Rosberg', constructor=>'Retired', age=>36);
l_driver_tab('rosberg') := l_driver_info;
-- even shorter
l_driver_info := driver_info('Fernando Alonso', 'Alpine', 40);
l_driver_tab('alonso') := l_driver_info;
dbms_output.put_line( l_driver_tab.count || ' driver(s) left in the Associative Array.');
l_key := l_driver_tab.first();
while l_key is not null
loop
dbms_output.put_line( l_key || ' => ' || l_driver_tab(l_key).full_name );
l_key := l_driver_tab.next( l_key );
end loop;
end;