Advertisement
cesarcardinale

M3106C BDA - TP1

Sep 14th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 4.21 KB | None | 0 0
  1. /* Première étape */
  2. /* Question 1 */
  3. SELECT COLUMN_NAME
  4. FROM USER_TAB_COLUMNS
  5. WHERE TABLE_NAME = 'PROF';
  6.  
  7. /* Question 2 */
  8. SELECT OBJECT_NAME
  9. FROM USER_OBJECTS
  10. WHERE OBJECT_TYPE = 'FUNCTION' OR OBJECT_TYPE = 'PROCEDURE';
  11.  
  12. /* Question 3 */
  13. SELECT *
  14. FROM USER_CONSTRAINTS
  15. WHERE CONSTRAINT_TYPE = 'R' OR CONSTRAINT_TYPE = 'P';
  16.  
  17. /* Question 4 */
  18. SELECT DISTINCT CONSTRAINT_NAME
  19. FROM USER_CONSTRAINTS
  20. JOIN USER_TAB_COLUMNS
  21. ON USER_CONSTRAINTS.TABLE_NAME = USER_TAB_COLUMNS.TABLE_NAME
  22. WHERE DATA_TYPE = 'NUMBER';
  23.  
  24. /* Question 5 */
  25. SELECT DISTINCT CONSTRAINT_NAME, COLUMN_NAME
  26. FROM USER_CONSTRAINTS
  27. JOIN USER_TAB_COLUMNS
  28. ON USER_CONSTRAINTS.TABLE_NAME = USER_TAB_COLUMNS.TABLE_NAME
  29. WHERE DATA_TYPE = 'NUMBER';
  30.  
  31. /* Question 6 */
  32. SELECT DISTINCT CONSTRAINT_NAME, COLUMN_NAME, DATA_TYPE
  33. FROM USER_CONSTRAINTS
  34. JOIN USER_TAB_COLUMNS
  35. ON USER_CONSTRAINTS.TABLE_NAME = USER_TAB_COLUMNS.TABLE_NAME
  36. WHERE DATA_TYPE = 'NUMBER';
  37.  
  38. /* Question 7 */
  39. SELECT *
  40. FROM USER_CONS_COLUMNS;
  41.  
  42. /* Question 8 */
  43. SELECT DISTINCT C1.TABLE_NAME, C1.COLUMN_NAME, C2.TABLE_NAME, C2.COLUMN_NAME
  44. FROM USER_TAB_COLUMNS C1
  45. JOIN USER_TAB_COLUMNS C2
  46. ON C1.COLUMN_NAME = C2.COLUMN_NAME
  47. WHERE C1.TABLE_NAME <> C2.TABLE_NAME;
  48.  
  49. /* Question 9 */
  50. SELECT DISTINCT C1.TABLE_NAME, C1.COLUMN_NAME, C2.TABLE_NAME, C2.COLUMN_NAME
  51. FROM USER_TAB_COLUMNS C1
  52. JOIN USER_TAB_COLUMNS C2
  53. ON C1.COLUMN_NAME = C2.COLUMN_NAME
  54. WHERE C1.TABLE_NAME != C2.TABLE_NAME;
  55.  
  56. /* Deuxième étape */
  57. /* Question 10 */
  58. CREATE
  59. VIEW PROF_INFO2
  60. AS
  61. SELECT DISTINCT PROF.NUM_PROF, PROF.NOM_PROF, PROF.PRENOM_PROF
  62. FROM PROF
  63. JOIN ENSEIGNT
  64. ON PROF.NUM_PROF = ENSEIGNT.NUM_PROF
  65. JOIN ETUDIANT
  66. ON ENSEIGNT.NUM_ET = ETUDIANT.NUM_ET
  67. WHERE ETUDIANT.ANNEE = '2';
  68.  
  69. /* Question 11 */
  70. CREATE
  71. VIEW DIS
  72. AS
  73. SELECT DISCIPLINE
  74. FROM MODULE
  75. WITH CHECK OPTION;
  76.  
  77. /* Question 12 */
  78. CREATE
  79. VIEW RESP
  80. AS
  81. SELECT DISTINCT MODULE.CODE, PROF.NUM_PROF
  82. FROM ENSEIGNT
  83. JOIN MODULE
  84. ON ENSEIGNT.CODE = MODULE.CODE
  85. JOIN PROF
  86. ON MODULE.RESP = PROF.NUM_PROF
  87. WITH CHECK OPTION;
  88.  
  89. /* Question 13 */
  90. CREATE
  91. VIEW ENSEIGNTVIEW
  92. AS
  93. SELECT ENSEIGNT.CODE, ENSEIGNT.NUM_ET, ENSEIGNT.NUM_PROF
  94. FROM ENSEIGNT
  95. WHERE ENSEIGNT.CODE IN (SELECT DISTINCT CODE
  96.                         FROM MODULE)
  97. AND ENSEIGNT.NUM_ET IN (SELECT DISTINCT NUM_ET
  98.                         FROM ETUDIANT)
  99. AND ENSEIGNT.NUM_PROF IN (SELECT DISTINCT NUM_PROF
  100.                           FROM PROF)
  101. WITH CHECK OPTION;
  102.  
  103. /* Question 14 */
  104. CREATE
  105. VIEW MODULEVIEW
  106. AS
  107. SELECT CODE, LIBELLE
  108. FROM MODULE
  109. WHERE CODE NOT IN (SELECT DISTINCT CODE
  110.                   FROM ENSEIGNT)
  111. AND CODE NOT IN (SELECT DISTINCT CODE
  112.                  FROM NOTATION)
  113. AND CODE NOT IN (SELECT DISTINCT CODEPERE
  114.                  FROM MODULE)
  115. AND CODE NOT IN (SELECT DISTINCT MAT_SPEC
  116.                  FROM PROF)
  117. WITH CHECK OPTION;
  118.  
  119. /* Troisième étape */
  120. /* Question 15 */
  121. GRANT SELECT
  122. ON ETUDIANT
  123. TO PUBLIC;
  124.  
  125. /* Question 16 */
  126. SELECT *
  127. FROM ET2044.ETUDIANT
  128. WHERE VILLE_ET = 'MARSEILLE';
  129.  
  130. INSERT INTO ET2044.ETUDIANT
  131. VALUES('5762','CARDINALE','CESAR','13012','MARSEILLE','2','2');
  132. COMMIT;
  133.  
  134. /* Question 17 */
  135. GRANT ALL
  136. ON PROF
  137. TO ET2044;
  138.  
  139. /* Quatrième étape */
  140. /* Questin 18 */
  141. DECLARE
  142.     CURSOR LIBMAT
  143.     IS
  144.     SELECT CODE, LIBELLE
  145.     FROM MODULE;
  146.    
  147.     PASDEMAT EXCEPTION;
  148.    
  149. BEGIN
  150.     OPEN LIBMAT;
  151.     IF (LIBMAT%NOTFOUND) THEN RAISE PASDEMAT;
  152.     END IF;
  153.     CLOSE LIBMAT;
  154.    
  155.     FOR I IN LIBMAT
  156.     LOOP
  157.         DBMS_OUTPUT.PUT_LINE(I.CODE || I.LIBELLE);
  158.     END LOOP;
  159.  
  160. EXCEPTION
  161.     WHEN PASDEMAT
  162.     THEN RAISE_APPLICATION_ERROR(-20090,'PAS DE MATIERE');
  163. END;
  164.  
  165. /* Question 19 */
  166. CREATE TABLE GROUPE( NUMERO NUMBER(3,0), EFFECTIF NUMBER(3,0), CONSTRAINT CP_GROUPE PRIMARY KEY (NUMERO));
  167.  
  168. DECLARE
  169.     NB_GROUPE NUMBER(1,0);
  170.     EFFECTIF GROUPE.EFFECTIF%TYPE;
  171.     AUCUN_ETUDIANT EXCEPTION;
  172. BEGIN
  173.   COMMIT;
  174.   SELECT COUNT(DISTINCT GROUPE) INTO NB_GROUPE FROM ETUDIANT WHERE ANNEE = 2;
  175.   IF NB_GROUPE = 0 THEN RAISE AUCUN_ETUDIANT;
  176.   END IF;
  177.   FOR i IN 1 .. NB_GROUPE
  178.   LOOP
  179.     SELECT COUNT(*) INTO EFFECTIF FROM ETUDIANT WHERE GROUPE = i AND ANNEE = 2;
  180.     INSERT INTO GROUPE VALUES (i, EFFECTIF);
  181.   END LOOP;
  182.   COMMIT;
  183. EXCEPTION
  184.   WHEN AUCUN_ETUDIANT THEN DBMS_OUTPUT.PUT_LINE('Il n''y a pas d''étudiant');
  185. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement