2020-06-15 22:56:57 -04:00
|
|
|
|
|
|
|
/* Pregunta 3*/
|
2020-06-09 10:23:08 -04:00
|
|
|
CREATE OR REPLACE TRIGGER correlative_increment BEFORE INSERT ON ciudad FOR EACH ROW
|
|
|
|
|
|
|
|
DECLARE
|
|
|
|
|
|
|
|
idCiudad number;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
SELECT MAX(id_ciudad) INTO idCiudad FROM ciudad;
|
|
|
|
:new.id_ciudad := idCiudad + 1;
|
2020-06-15 22:56:57 -04:00
|
|
|
END;
|
|
|
|
|
|
|
|
/* Pregunta 4 */
|
|
|
|
|
|
|
|
CREATE OR REPLACE TRIGGER Validacion_Pre_Competencia BEFORE INSERT ON PARTICIPAR_COMPETENCIA
|
|
|
|
FOR EACH ROW
|
|
|
|
DECLARE
|
|
|
|
CURSOR participar_preco
|
|
|
|
IS SELECT PPC.id_precompetencia
|
|
|
|
FROM PARTICIPAR_PRECOMPETENCIA PPC
|
|
|
|
LEFT JOIN PRECOMPETENCIA PC ON PC.id_precompetencia = PPC.id_precompetencia
|
|
|
|
WHERE PPC.id_atleta = :NEW.id_atleta AND pc.competencia = :NEW.id_competencia;
|
|
|
|
|
|
|
|
id_precompetencia PARTICIPAR_PRECOMPETENCIA.id_precompetencia%TYPE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
OPEN participar_preco;
|
|
|
|
FETCH participar_preco into 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');
|
|
|
|
END IF;
|
|
|
|
CLOSE participar_preco;
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
|
|
|
|
INSERT INTO "PARTICIPAR_COMPETENCIA" (ID_COMPETENCIA, ID_ATLETA, FECHA) VALUES ('1', '21', TO_DATE('2020-07-09 00:00:00', 'YYYY-MM-DD HH24:MI:SS'));
|
|
|
|
|
|
|
|
INSERT INTO "PARTICIPAR_PRECOMPETENCIA" (ID_PRECOMPETENCIA, ID_ATLETA, PUNTAJE, FECHA) VALUES ('3', '2', '100', TO_DATE('2020-06-27 00:00:00', 'YYYY-MM-DD HH24:MI:SS'));
|
|
|
|
|
|
|
|
INSERT INTO "PARTICIPAR_COMPETENCIA" (ID_COMPETENCIA, ID_ATLETA, FECHA) VALUES ('1', '21', TO_DATE('2020-07-09 00:00:00', 'YYYY-MM-DD HH24:MI:SS'));
|
|
|
|
|
|
|
|
|
2020-06-26 21:57:36 -04:00
|
|
|
/* Pregunta 5 */
|
|
|
|
|
|
|
|
CREATE OR REPLACE TRIGGER CALCULAR_VALOR_DELEGACION
|
|
|
|
BEFORE INSERT OR UPDATE
|
|
|
|
ON HOSPEDAR
|
|
|
|
|
|
|
|
FOR EACH ROW
|
|
|
|
DECLARE
|
|
|
|
atletas DELEGACION.CANTIDAD_ATLETAS%TYPE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF INSERTING THEN
|
|
|
|
SELECT CANTIDAD_ATLETAS INTO atletas
|
|
|
|
FROM DELEGACION WHERE (ID_DELEGACION = :NEW.ID_DELEGACION);
|
|
|
|
|
|
|
|
:NEW.PRECIO_DELEGACION := atletas * :NEW.PRECIO_ATLETA;
|
|
|
|
ELSIF UPDATING THEN
|
|
|
|
SELECT CANTIDAD_ATLETAS INTO atletas
|
|
|
|
FROM DELEGACION WHERE (ID_DELEGACION = :NEW.ID_DELEGACION);
|
|
|
|
|
|
|
|
:NEW.PRECIO_DELEGACION := atletas * :NEW.PRECIO_ATLETA;
|
|
|
|
END IF;
|
|
|
|
END;
|
|
|
|
|
|
|
|
INSERT INTO HOSPEDAR (ID_HOTEL, ID_DELEGACION, PRECIO_DELEGACION, PRECIO_ATLETA) VALUES (1, 1, 5, 50000);
|
|
|
|
UPDATE HOSPEDAR SET PRECIO_DELEGACION = 5 WHERE (ID_HOTEL = 1 AND ID_DELEGACION = 1);
|
|
|
|
UPDATE HOSPEDAR SET PRECIO_ATLETA = 50000 WHERE (ID_HOTEL = 1 AND ID_DELEGACION = 1);
|