Настройка Oracle :
create or replace type personal as OBJECT(
name varchar2(30),
last_name varchar2(30),
charge varchar2(50),
mail varchar2(100)
);
/
create or replace type personalarray as varray(3) of personal;
/
create or replace type contact_data as OBJECT(
mail varchar2(40),
fax varchar2(20),
personale personalarray
);
/
create table test_1(
id int,
contact contact_data
);
/
INSERT INTO test_1 (
id,
contact
) VALUES (
1,
contact_data(
'mail',
'fax',
personalarray(
personal( 'name1', 'lastname1', 'charge1', 'mail1' )
)
)
);
Вы можете создать функцию для обновления значения:
CREATE FUNCTION updateContactDataPersonal(
in_contact IN test_1.contact%type,
in_index IN number,
in_personal IN personal
) RETURN contact_data
IS
p_contact contact_data := in_contact;
BEGIN
IF ( p_contact IS NULL ) THEN
p_contact := contact_data( NULL, NULL, personalarray() );
END IF;
IF ( p_contact.personale IS NULL ) THEN
p_contact.personale := personalarray();
END IF;
IF ( in_index < 1 OR in_index > 3 ) THEN
raise_application_error( -20001, 'Invalid index' );
END IF;
IF ( p_contact.personale.COUNT < in_index ) THEN
p_contact.personale.extend( in_index - p_contact.personale.COUNT );
END IF;
p_contact.personale( in_index ) := in_personal;
RETURN p_contact;
END;
/
Обновление :
UPDATE test_1
SET contact = updateContactDataPersonal( contact, 3, personal( 'name3', 'lastname3', 'charge3', 'mail3' ) )
WHERE id = 1;
Запрос :
SELECT id,
t.contact.mail,
t.contact.fax,
p.name,
p.last_name,
p.charge,
p.mail
FROM test_1 t
CROSS JOIN
TABLE( t.contact.personale ) p;
Вывод :
ID CONTACT.MAIL CONTACT.FAX NAME LAST_NAME CHARGE MAIL
-- ------------ ----------- ----- --------- ------- -----
1 mail fax name1 lastname1 charge1 mail1
1 mail fax - - - -
1 mail fax name3 lastname3 charge3 mail3