add trigger 5

This commit is contained in:
Chris Cromer 2020-06-26 21:57:36 -04:00
parent 8736f72708
commit 072f68dbca

View File

@ -46,3 +46,29 @@ INSERT INTO "PARTICIPAR_COMPETENCIA" (ID_COMPETENCIA, ID_ATLETA, FECHA) VALUES (
/* 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);