Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Utilisation de deux curseurs un pour Adhérent et un autre pour Paquetage
- La fonction retourne 0 si ok et -1 si erreur, elle appellera la fonction maj_adherent
- SET VERIFY OFF
- SET SERVER OUTPUT ON
- CREATE OR REPLACE FUNCTION generer_prets
- (numsortie IN NUMBER)
- RETURN NUMBER
- IS
- CURSOR cadherent IS
- SELECT no_adherent
- FROM Participe
- WHERE no_sortie=numsortie AND payee='V';
- CURSOR cpaquetage IS
- SELECT no_paquetage
- FROM pret
- WHERE no_paquetage=paquetage_utilise AND date_retour!=NULL;
- paquetage_utilise paquetage.no_paquetage%TYPE;
- caution_paquetage paquetage.caution%TYPE;
- BEGIN
- SELECT no_paquetage INTO paquetage_utilise
- FROM utilise
- WHERE no_sortie=numsortie;
- SELECT caution INTO caution_paquetage
- FROM paquetage
- WHERE no_paquetage = paquetage_utilise;
- FOR lig_adherent IN cadherent LOOP
- IF cadherent%ROWCOUNT<1 THEN
- dbms-output.put_line(' AUCUN ADHERENT NE PARTICIPE A CETTE SORTIE ' );
- RETURN -1;
- END IF;
- FOR lig_paquetage IN cpaquetage LOOP
- IF cpaquetage%ROWCOUNT<1 THEN
- dbms-output.put_line(' PAS ASSEZ DE PAQUETAGES ' );
- RETURN -1;
- END IF;
- INSERT INTO pret
- VALUES ( sysdate, lig_paquetage.no_paquetage, lig_adherent.no_adherent, NULL );
- EXIT;
- END LOOP;
- UPDATE adherent
- SET credits := credits - caution_paquetage
- WHERE no_adherent = lig_adherent.no_adherent;
- END LOOP;
- RETURN 0;
- EXCEPTION
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement