Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.76 KB | None | 0 0
  1. 3 - Pour effectuer une sortie, le club prête à chaque adhérent un paquetage (corde,casque,lampe ...) moyennant le dépôt d une caution qui est prélevée sur son crédit. Développer la fonction generer_prets(numsortie IN NUMBER) qui affecte un paquetage à chaque participant à une sortie et prélève sur son crédit le montant de la caution.
  2.  
  3. Utilisation de deux curseurs un pour Adhérent et un autre pour Paquetage
  4. La fonction retourne 0 si ok et -1 si erreur, elle appellera la fonction maj_adherent
  5.  
  6. SET VERIFY OFF
  7. SET SERVER OUTPUT ON
  8.  
  9. CREATE OR REPLACE FUNCTION generer_prets
  10.     (numsortie IN NUMBER)
  11. RETURN NUMBER
  12.  
  13. IS
  14.     CURSOR cadherent IS
  15.         SELECT no_adherent
  16.         FROM Participe
  17.         WHERE no_sortie=numsortie AND payee='V';
  18.    
  19.     CURSOR cpaquetage IS
  20.         SELECT no_paquetage
  21.         FROM pret
  22.         WHERE no_paquetage=paquetage_utilise AND date_retour!=NULL;
  23.  
  24.     paquetage_utilise paquetage.no_paquetage%TYPE;
  25.     caution_paquetage paquetage.caution%TYPE;
  26. BEGIN
  27.  
  28.     SELECT no_paquetage INTO paquetage_utilise
  29.     FROM utilise
  30.     WHERE no_sortie=numsortie;
  31.  
  32.     SELECT caution INTO caution_paquetage
  33.     FROM paquetage
  34.     WHERE no_paquetage = paquetage_utilise;
  35.  
  36.     FOR lig_adherent IN cadherent LOOP
  37.  
  38.         IF cadherent%ROWCOUNT<1 THEN
  39.             dbms-output.put_line(' AUCUN ADHERENT NE PARTICIPE A CETTE SORTIE ' );
  40.             RETURN -1;
  41.         END IF;
  42.  
  43.         FOR lig_paquetage IN cpaquetage LOOP
  44.  
  45.             IF cpaquetage%ROWCOUNT<1 THEN
  46.                 dbms-output.put_line(' PAS ASSEZ DE PAQUETAGES ' );
  47.                 RETURN -1;
  48.             END IF;
  49.  
  50.             INSERT INTO pret
  51.  
  52.             VALUES ( sysdate, lig_paquetage.no_paquetage, lig_adherent.no_adherent, NULL );
  53.             EXIT;
  54.         END LOOP;
  55.    
  56.     UPDATE adherent
  57.     SET credits := credits - caution_paquetage
  58.     WHERE no_adherent = lig_adherent.no_adherent;
  59.  
  60.     END LOOP;
  61.  
  62.     RETURN 0;
  63.  
  64.  
  65. EXCEPTION
  66.  
  67. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement