olimpicos/trigger.sql

63 lines
1.8 KiB
MySQL
Raw Normal View History

2020-06-26 22:47:31 -04:00
-- Trigger 3
CREATE OR REPLACE TRIGGER CORRELATIVE_INCREMENT_CIUDAD
BEFORE INSERT
ON CIUDAD
2020-06-15 22:56:57 -04:00
2020-06-26 22:47:31 -04:00
FOR EACH ROW
2020-06-09 10:23:08 -04:00
DECLARE
2020-06-26 22:47:31 -04:00
v_id_ciudad CIUDAD.ID_CIUDAD%TYPE;
2020-06-09 10:23:08 -04:00
BEGIN
2020-06-26 22:47:31 -04:00
SELECT MAX(ID_CIUDAD) INTO v_id_ciudad FROM CIUDAD;
:NEW.ID_CIUDAD := v_id_ciudad + 1;
2020-06-15 22:56:57 -04:00
END;
2020-06-26 22:47:31 -04:00
-- Trigger 4
CREATE OR REPLACE TRIGGER VALIDACION_PRE_COMPETENCIA
BEFORE INSERT
ON PARTICIPAR_COMPETENCIA
2020-06-15 22:56:57 -04:00
FOR EACH ROW
DECLARE
2020-06-26 22:47:31 -04:00
CURSOR PARTICIPAR_PRECO IS
SELECT PPC.ID_PRECOMPETENCIA
2020-06-15 22:56:57 -04:00
FROM PARTICIPAR_PRECOMPETENCIA PPC
2020-06-26 22:47:31 -04:00
LEFT JOIN PRECOMPETENCIA PC ON (PC.ID_PRECOMPETENCIA = PPC.ID_PRECOMPETENCIA)
WHERE (PPC.ID_ATLETA = :NEW.ID_ATLETA AND PC.COMPETENCIA = :NEW.ID_COMPETENCIA);
2020-06-15 22:56:57 -04:00
2020-06-26 22:47:31 -04:00
v_id_precompetencia PARTICIPAR_PRECOMPETENCIA.ID_PRECOMPETENCIA%TYPE;
2020-06-15 22:56:57 -04:00
BEGIN
2020-06-26 22:47:31 -04:00
OPEN PARTICIPAR_PRECO;
FETCH PARTICIPAR_PRECO INTO v_id_precompetencia;
IF PARTICIPAR_PRECO%FOUND THEN
DBMS_OUTPUT.PUT_LINE('EL ATLETA HA PARTICIPADO EN PRECOMPETENCIAS ASOCIADAS');
ELSE
RAISE_APPLICATION_ERROR(-20120, 'NO SE PUEDE INSERTAR, EL ATLETA NO POSEE PRECOMPETENCIAS ASOCIADAS A LA COMPETENCIA');
2020-06-15 22:56:57 -04:00
END IF;
2020-06-26 22:47:31 -04:00
CLOSE PARTICIPAR_PRECO;
2020-06-15 22:56:57 -04:00
END;
2020-06-26 22:47:31 -04:00
-- Trigger 5
2020-06-26 21:57:36 -04:00
CREATE OR REPLACE TRIGGER CALCULAR_VALOR_DELEGACION
BEFORE INSERT OR UPDATE
ON HOSPEDAR
FOR EACH ROW
DECLARE
2020-06-26 22:47:31 -04:00
v_atletas DELEGACION.CANTIDAD_ATLETAS%TYPE;
2020-06-26 21:57:36 -04:00
BEGIN
IF INSERTING THEN
2020-06-26 22:47:31 -04:00
SELECT CANTIDAD_ATLETAS INTO v_atletas
2020-06-26 21:57:36 -04:00
FROM DELEGACION WHERE (ID_DELEGACION = :NEW.ID_DELEGACION);
2020-06-26 22:47:31 -04:00
:NEW.PRECIO_DELEGACION := v_atletas * :NEW.PRECIO_ATLETA;
2020-06-26 21:57:36 -04:00
ELSIF UPDATING THEN
2020-06-26 22:47:31 -04:00
SELECT CANTIDAD_ATLETAS INTO v_atletas
2020-06-26 21:57:36 -04:00
FROM DELEGACION WHERE (ID_DELEGACION = :NEW.ID_DELEGACION);
2020-06-26 22:47:31 -04:00
:NEW.PRECIO_DELEGACION := v_atletas * :NEW.PRECIO_ATLETA;
2020-06-26 21:57:36 -04:00
END IF;
END;