Using the SQL*Plus of Oracle 8i Personal Edition:
CREATE TABLE COBERTURA (
NombreCob VARCHAR(30) NOT NULL,
TelCob INTEGER NULL
CONSTRAINT positivo560
CHECK (TelCob >= 1),
DirCob VARCHAR(30) NULL,
CONSTRAINT XPKCOBERTURA
PRIMARY KEY (NombreCob)
);
CREATE TABLE PARTICIPANTE (
NroDoc INTEGER NOT NULL
CONSTRAINT positivo561
CHECK (NroDoc >= 1),
NombreCob VARCHAR(30) NULL,
NyAp VARCHAR(30) NOT NULL,
Dir VARCHAR(30) NOT NULL,
Tel INTEGER NULL
CONSTRAINT positivo562
CHECK (Tel >= 1),
Mail VARCHAR(30) NULL,
Localidad VARCHAR(30) NOT NULL,
Pcia VARCHAR(30) NOT NULL,
CodPostal VARCHAR(10) NULL,
Sexo CHAR(1) NOT NULL
CONSTRAINT sexo49
CHECK (Sexo = 'f' or Sexo = 'm'),
Edad SMALLINT NOT NULL
CONSTRAINT positivo563
CHECK (Edad >= 1),
CONSTRAINT XPKPARTICIPANTE
PRIMARY KEY (NroDoc),
CONSTRAINT posee
FOREIGN KEY (NombreCob)
REFERENCES COBERTURA
);
create trigger tI_PARTICIPANTE after INSERT on PARTICIPANTE for each row
declare numrows INTEGER;
begin
insert into COBERTURA (NombreCob)
select NombreCob
from PARTICIPANTE
where
:new.NombreCob is not null and
not exists (
select * from COBERTURA
where
:new.NombreCob = COBERTURA.NombreCob
);
end;
/
Inserting...
SQL> INSERT INTO PARTICIPANTE (NroDoc, NombreCob, NyAp, Dir, Tel, Mail, Localidad, Pcia, CodPostal,
Sexo, Edad)
2 values (21, 'nomcob', 'nyap1', 'dir1', 23, 'mail1', 'loca1', 'pci', 7000, 'f', 23);
INSERT INTO PARTICIPANTE (NroDoc, NombreCob, NyAp, Dir, Tel, Mail, Localidad, Pcia, CodPostal, Sexo,
*
ERROR at line 1:
ORA-04091: table SYSTEM.PARTICIPANTE is mutating, trigger/function may not see
it
ORA-06512: at "SYSTEM.TI_PARTICIPANTE", line 3
ORA-04088: error during execution of trigger 'SYSTEM.TI_PARTICIPANTE'
What´s the problem?
Then I drop the trigger and I create the following trigger:
create trigger tI_PARTICIPANTE after INSERT on PARTICIPANTE for each row
declare numrows INTEGER;
DECLARE Y VARCHAR(20);
begin
insert into tmp_participante VALUES (:NEW.NombreCob);
CURSOR C IS SELECT DISTINCT NombreCob FROM tmp_participante;
OPEN C;
FETCH C INTO Y,
WHILE C%found LOOP
insert into COBERTURA (Y)
where
Y is not null and
not exists (select * from COBERTURA where Y = COBERTURA.NombreCob);
FETCH C INTO Y
END LOOP;
CLOSE C;
DELETE FROM tmp_presentacion;
end;
/
Warning: Trigger created with compilation errors.
What´s the problem? Which are the possible reasons of this warning?