Hi, i have de following error on this code:
--Exercici 1
Create type Adreca_T As Object(
carrer varchar2(80),
numero number(3),
poblacio varchar2(80),
codiPostal number(5)
);
Create type E_Empleat_T As Object(
Nif varchar2(9),
Nom varchar2(50),
adreça Adreca_T,
dataNaixement date,
sou number(5),
cap REF E_Empleat_T
);
create table TaulaEmpleats of E_Empleat_T;
insert into TaulaEmpleats values ('38234567A','Josep Verdú Bargalló',
Adreca_T('Estanislau Figueres',25,'Tarragona',43002),
to_date('12/12/1973','dd/mm/yyyy'),4500,null);
insert into TaulaEmpleats values ('39311345X','Pere Garcia Llorens',
Adreca_T('Blanca dAnjou',45,'Tarragona',43002),
to_date('05/07/1980','dd/mm/yyyy'),1000,(select REF(E) from TaulaEmpleats E where nif = '38234567A'));
--Exercici 2
CREATE TYPE telefons_T is VARRAY(5) of varchar2(10);
Create or replace type E_Empleat2_T As Object(
Nif varchar2(9),
Nom varchar2(50),
adreça Adreca_T,
dataNaixement date,
sou number(5),
cap REF E_Empleat2_T,
Telefon Telefons_t,
member procedure afegirTelefon(Telefon in varchar2),
member procedure modificarTelefon (telefonold in varchar2, telefonnew in varchar2)
);
drop table TaulaEmpleats;
create table TaulaEmpleats of E_Empleat2_T;
insert into TaulaEmpleats values ('38234567A','Josep Verdú Bargalló',
Adreca_T('Estanislau Figueres',25,'Tarragona',43002),
to_date('12/12/1973','dd/mm/yyyy'),4500,null,null);
insert into TaulaEmpleats values ('39311345X','Pere Garcia Llorens',
Adreca_T('Blanca dAnjou',45,'Tarragona',43002),
to_date('05/07/1980','dd/mm/yyyy'),1000,
(select REF(E) from TaulaEmpleats E where nif = '38234567A'),null);
--Exercici 3
Create or Replace Type body E_Empleat2_T as
member PROCEDURE afegirTelefon (telefon VARCHAR2) as
taula_af telefons_T;
numero number(5);
begin
select telefon into taula_af from TaulaEmpleats where nif =SELF.Nif;
numero:=taula_af.Count;
taula_af.EXTEND();
taula_af(numero+1):=Telefon;
update TaulaEmpleats set telefon=taula_af where nif =SELF.Nif;
end afegirTelefon;
member PROCEDURE modificarTelefon (telefonold VARCHAR2, telefonnew VARCHAR2) as
taula_af telefons_T;
i number(5);
fi boolean;
begin
select telefon into taula_af from TaulaEmpleats where nif =SELF.Nif;
i:=1;
fi:=false;
while (i<=taula_af.COUNT and not fi) loop
if (taula_af(i) = telefonold) then
taula_af(i):=telefonnew;
fi:=true;
end if;
i:=i+1;
end loop;
Update TaulaEmpleats set telefon=taula_af where nif=SELF.Nif;
end modificarTelefon;
end;
declare
x E_Empleat2_T;
begin
select value(E) into x from TaulaEmpleats E where E.nif = '39311345X';
x.afegirTelefon('659312111');
update TaulaEmpleats E set E= x where E.nif='39311345X';
End;
The problem, was in "Exercici 3"
The banner
Error que empieza en la línea: 1 del comando :
declare
x E_Empleat2_T;
begin
select value(E) into x from TaulaEmpleats E where E.nif = '39311345X';
x.afegirTelefon('659312111');
update TaulaEmpleats E set E= x where E.nif='39311345X';
End;
Ther error:
Informe de error -
ORA-06531: Reference to uninitialized collection
ORA-06512: at "SYSTEM.E_EMPLEAT2_T", line 8
ORA-06512: at line 5
06531. 00000 - "Reference to uninitialized collection"
*Cause: An element or member function of a nested table or varray
was referenced (where an initialized collection is needed)
without the collection having been initialized.
*Action: Initialize the collection with an appropriate constructor
or whole-object assignment.
Any help will be appreciated.