Oracle
 sql >> Base de données >  >> RDS >> Oracle

Est-il possible de passer des objets à la procédure du package PL SQL en tant que paramètres ?

CREATE OR REPLACE TYPE t_parsed_name as object (
name_prefix varchar2(50),
name_first varchar2(50),
name_middle varchar2(50),
name_last varchar2(100),
name_suffix varchar2(50)
);

CREATE OR REPLACE TYPE T_PARSED_NAME_ARY as table of t_parsed_name;

create or replace procedure test_parsed_names(i_parsed_name_ary in t_parsed_name_ary) as
    idx pls_integer;
begin
    idx := i_parsed_name_ary.first;
    loop
        exit when idx is null;
        dbms_output.put_line('First name: ' || i_parsed_name_ary(idx).name_first || ', Last name: ' || i_parsed_name_ary(idx).name_last);
        idx := i_parsed_name_ary.next(idx);
    end loop;
end;

----------------------------------------
-- example using above procedure
declare
    l_parsed_name t_parsed_name;
    l_parsed_name_ary t_parsed_name_ary;
begin
  l_parsed_name_ary := t_parsed_name_ary();
  l_parsed_name_ary.extend(3);

  -- create some parsed names and add to array
  l_parsed_name := t_parsed_name('Mr','Joe','T','Blow','Jr');
  l_parsed_name_ary(1) := l_parsed_name;
  l_parsed_name := t_parsed_name('Mrs','Jane','','Doe','');
  l_parsed_name_ary(2) := l_parsed_name;
  l_parsed_name := t_parsed_name('','Betty','','Boop','');
  l_parsed_name_ary(3) := l_parsed_name;

  -- test the array (call procedure with object type array parameter)
  test_parsed_names(l_parsed_name_ary);
end;