Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Oracle »

Trigger

Estas en el tema de Trigger en el foro de Oracle en Foros del Web. -------------------------------------------------------------------------------- buenas tardes tengo un problema con este trigger os pongo las tablas y a ver si alquien me puede echar un cable: create table ...
  #1 (permalink)  
Antiguo 16/01/2007, 06:05
 
Fecha de Ingreso: diciembre-2006
Mensajes: 10
Antigüedad: 17 años, 4 meses
Puntos: 0
Trigger

--------------------------------------------------------------------------------

buenas tardes tengo un problema con este trigger os pongo las tablas y a ver si alquien me puede echar un cable:

create table SINTONIA (
codigo number(4) not null unique,
tipo varchar2(4),
publico varchar2(30),
tarifa number(10),
ecualizacion varchar2(4),
constraint pk_sintonia primary key(codigo),
constraint tipo_valido check (tipo in ('EDIT', 'KOKA', 'NORM')),
constraint ecualizacion_valida check (ecualizacion in ('CCIR', 'NAB'))
);

create table USO_SINTONIA (
fecha_inicio date,
fecha_fin date not null unique,
codigo_uso number(4) not null,
constraint pk_uso_sintonia primary key( fecha_fin,codigo_uso),
constraint pk_uso2 foreign key(codigo_uso) references SINTONIA(codigo) on delete cascade,
constraint fechas_validas check (fecha_fin = ADD_MONTHS (fecha_inicio,12))
);


Y EL TRIGGER


create trigger INSERTAR_USO_SINTONIA
before insert on USO_SINTONIA
for each row
begin
select codigo, codigo_uso
from USO_SINTONIA, SINTONIA
where USO_SINTONIA.codigo_uso = SINTONIA.codigo;

exception
if no_data_found then
insert into SINTONIA(codigo) values (:new.uso_sintonia);
end;

.
run;

select codigo, codigo_uso
from USO_SINTONIA, SINTONIA
where USO_SINTONIA.codigo_uso = SINTONIA.codigo;

insert into USO_SINTONIA values ('02-Jan-2005','02-Jan-2006','0009');

CUANDO LO EJECUTO ME DA EL ERROR

insert into USO_SINTONIA values ('02-Jan-2005','02-Jan-2006','0009')
*
ERROR at line 1:
ORA-04098: trigger 'INSERTAR_USO_SINTONIA' is invalid and failed re-validation


AYUDAAAAAAA
  #2 (permalink)  
Antiguo 16/01/2007, 09:24
 
Fecha de Ingreso: junio-2006
Mensajes: 87
Antigüedad: 17 años, 10 meses
Puntos: 0
Re: Trigger

Pues el error te lo dice: el trigger tiene errores de compilación y no se puede ejecutar. Te pongo lo que veo. Que quieres hacer exactamente con el trigger?

Código:
create trigger INSERTAR_USO_SINTONIA
before insert on USO_SINTONIA
for each row
begin

-----
--ESTA SELECT AQUI NO SE UTILIZA PARA NADA ADEMAS DA ERROR 
--PORQUE TIENES QUE UTILIZAR UN SELECT .... INTO.... FROM... WHERE...
-----

select codigo, codigo_uso
from USO_SINTONIA, SINTONIA
where USO_SINTONIA.codigo_uso = SINTONIA.codigo;

exception

--TIENE QUE SER WHEN NO_DATA_FOUND THEN

if no_data_found then  
insert into SINTONIA(codigo) values (:new.uso_sintonia);
end;
  #3 (permalink)  
Antiguo 16/01/2007, 14:54
 
Fecha de Ingreso: diciembre-2006
Mensajes: 10
Antigüedad: 17 años, 4 meses
Puntos: 0
Re: Trigger

pues quiero que si al insertar una tupla en la tabla uso_sintonia si el codigo_uso no esta en la tabla sintonia, primero vaya a la tabla sintonia y lo inserte..
  #4 (permalink)  
Antiguo 16/01/2007, 19:46
Avatar de kikolice  
Fecha de Ingreso: marzo-2004
Mensajes: 1.510
Antigüedad: 20 años, 1 mes
Puntos: 7
Re: Trigger

select codigo, codigo_uso
from USO_SINTONIA, SINTONIA
where USO_SINTONIA.codigo_uso = SINTONIA.codigo;

como que te hace falta una parte en el where no???

"uso_sintonia si el codigo_uso no esta en la tabla sintonia, primero vaya a la tabla sintonia y lo inserte.."

primero deberas crear un constraint entre estas dos tablas

"run;"

a caray y ese comando de donde lo sacaste??
__________________
Blogzote.com :-) Mi blog
  #5 (permalink)  
Antiguo 17/01/2007, 02:22
 
Fecha de Ingreso: junio-2006
Mensajes: 87
Antigüedad: 17 años, 10 meses
Puntos: 0
Re: Trigger

Prueba con algo asi:

SELECT 1
INTO VEXISTE
FROM SINTONIA
WHERE SINTONIA.codigo=:NEW.USO_SINTONIA;

EXCEPTION

WHEN no_data_found then
insert into SINTONIA(codigo) values (:new.uso_sintonia);
END;

En la select no utilices la tabla sobre la que va el trigger porque te dará error de tabla mutante
  #6 (permalink)  
Antiguo 17/01/2007, 06:48
 
Fecha de Ingreso: diciembre-2006
Mensajes: 10
Antigüedad: 17 años, 4 meses
Puntos: 0
Re: Trigger

Cita:
Iniciado por seanchan Ver Mensaje
Prueba con algo asi:

SELECT 1
INTO VEXISTE
FROM SINTONIA
WHERE SINTONIA.codigo=:NEW.USO_SINTONIA;

EXCEPTION

WHEN no_data_found then
insert into SINTONIA(codigo) values (:new.uso_sintonia);
END;

En la select no utilices la tabla sobre la que va el trigger porque te dará error de tabla mutante

gracias pero me sigue dando error de compilacion el trigger
  #7 (permalink)  
Antiguo 17/01/2007, 08:47
 
Fecha de Ingreso: junio-2006
Mensajes: 87
Antigüedad: 17 años, 10 meses
Puntos: 0
Re: Trigger

Cita:
Iniciado por kkikka Ver Mensaje
gracias pero me sigue dando error de compilacion el trigger
Tienes que declarar la variable VEXISTE NUMBER(1);

Y si das algo mas de información (el error) tal vez te podamos decir por donde va el error.
  #8 (permalink)  
Antiguo 17/01/2007, 09:03
 
Fecha de Ingreso: diciembre-2006
Mensajes: 10
Antigüedad: 17 años, 4 meses
Puntos: 0
Re: Trigger

ESTO ES LO UNICO QUE ME PONE

DOC>*/
1 create trigger INSERTAR_USO_SINTONIA
2 before insert on USO_SINTONIA
3 for each row
4 declare
5 VEXISTE number(1);
6 begin
7 select 1
8 into VEXISTE
9 from SINTONIA
10 where SINTONIA.codigo = :new.USO_SINTONIA;
11
12 exception
13 when no_data_found then
14 insert into SINTONIA(codigo) values (:new.uso_sintonia);
15 end;
16*

Warning: Trigger created with compilation errors.


insert into USO_SINTONIA values ('02-Jan-2005','02-Jan-2006','0009')
*
ERROR at line 1:
ORA-04098: trigger 'INSERTAR_USO_SINTONIA' is invalid and failed re-validation
  #9 (permalink)  
Antiguo 17/01/2007, 10:00
 
Fecha de Ingreso: junio-2006
Mensajes: 87
Antigüedad: 17 años, 10 meses
Puntos: 0
Re: Trigger

Prueba con:
create or replace trigger INSERTAR_USO_SINTONIA
before insert on USO_SINTONIA
for each row

declare
VEXISTE number(1);
begin
select 1
into VEXISTE
from SINTONIA
where SINTONIA.codigo = :new.USO_SINTONIA;
exception
when no_data_found then
vExiste:=0;
end; -->> falta el end del exception
end;

Si te da error el error Warning: Trigger created with compilation errors.
Ejecuta en la consola: show errors
y te mostrara mas detalles del error de compilacion
  #10 (permalink)  
Antiguo 17/01/2007, 13:05
 
Fecha de Ingreso: diciembre-2006
Mensajes: 10
Antigüedad: 17 años, 4 meses
Puntos: 0
Re: Trigger

este es el error

7/26
PLS-00049: bad bind variable 'NEW.USO_SINTONIA'

11/39
PLS-00049: bad bind variable 'NEW.USO_SINTONIA'
  #11 (permalink)  
Antiguo 17/01/2007, 13:40
 
Fecha de Ingreso: diciembre-2006
Mensajes: 10
Antigüedad: 17 años, 4 meses
Puntos: 0
Re: Trigger

Ya Funciona Muchas Graciasss
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:38.