Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. CREATE OR REPLACE TRIGGER SUPR_MAT BEFORE DELETE ON MODULE FOR EACH ROW
  2. DECLARE
  3. enseigne NUMBER (4,0);
  4. BEGIN
  5. SELECT COUNT(*) INTO enseigne FROM ENSEIGNT WHERE ENSEIGNT.CODE = :old.CODE;
  6. IF enseigne > 0 THEN
  7. RAISE_APPLICATION_ERROR(-20000, 'Erreur : en cours d enseignement');
  8. END IF;
  9. END;
  10.  
  11. CREATE OR REPLACE TRIGGER CREA_MAT BEFORE INSERT ON MODULE FOR EACH ROW
  12. DECLARE
  13. enseigne NUMBER (4,0);
  14. BEGIN
  15. SELECT COUNT(*) INTO enseigne FROM ENSEIGNT WHERE ENSEIGNT.CODE = :new.CODE;
  16. IF enseigne > 0 THEN
  17. RAISE_APPLICATION_ERROR(-20001, 'Erreur : en cours d enseignement');
  18. END IF;
  19. END;
  20.  
  21. DELETE FROM MODULE WHERE CODE = 'BD';
  22. INSERT INTO MODULE VALUES ('baba');
  23.  
  24. CREATE OR REPLACE TRIGGER UpNote BEFORE INSERT OR UPDATE ON NOTATION
  25. BEGIN
  26. IF :new.MOY_CC IS NULL THEN
  27. :new.MOY_CC := 0;
  28. END IF;
  29. IF :new.MOY_TEST IS NULL THEN
  30. :new.MOY_TEST := 0;
  31. END IF;
  32. END;
  33.  
  34. create or replace trigger ajnote before insert or update on notation
  35. for each row
  36. declare
  37. nb number (4,0);
  38. begin
  39. select count(*) into nb from enseignt where code = :new.code and num_et = :new.num_et;
  40. if nb = 0 then
  41. RAISE_APPLICATION_ERROR(-20002, 'pas enseigne');
  42. end if;
  43. end;
  44.  
  45. create or replace trigger coefc before insert or update on module
  46. for each row
  47. declare
  48. tot number(4,0);
  49. begin
  50. tot := :new.coeff_cc + :new.coeff_test;
  51. if tot != 100 then
  52. RAISE_APPLICATION_ERROR(-20002, 'pas 100');
  53. end if;
  54. end;
  55.  
  56. CREATE TABLE GROUPE (ANNEE NUMBER(2,0), NUMERO NUMBER(1,0), EFFECTIF NUMBER(3,0));
  57. DROP TABLE GROUPE;
  58. DECLARE
  59. cursor grps is select groupe, annee, count(*) compt from etudiant group by groupe, annee;
  60. BEGIN
  61. for it in grps
  62. loop
  63. insert into groupe values (it.annee, it.groupe, it.compt);
  64. end loop;
  65. END;
  66.  
  67. SELECT * from groupe;
  68.  
  69.  
  70. CREATE OR REPLACE TRIGGER upetu before insert or update or delete on etudiant
  71. FOR EACH ROW
  72. BEGIN
  73. if :new.groupe = null then
  74. select numero into :new.groupe from groupe where effectif in (
  75. select min(effectif) from groupe);
  76. end if;
  77. if inserting then
  78. UPDATE groupe set effectif = effectif + 1 where numero = :new.groupe;
  79. end if;
  80. if updating then
  81. UPDATE groupe set effectif = effectif + 1 where numero = :new.groupe;
  82. UPDATE groupe set effectif = effectif - 1 where numero = :old.groupe;
  83. end if;
  84. if deleting then
  85. UPDATE groupe set effectif = effectif - 1 where numero = :old.groupe;
  86. end if;
  87. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement