parent
845d271a2e
commit
d9da1b58a4
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,150 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define size_t long
|
||||
|
||||
EXEC SQL INCLUDE SQLCA.H;
|
||||
EXEC SQL INCLUDE SQLDA.H;
|
||||
EXEC SQL INCLUDE ORACA.H;
|
||||
|
||||
|
||||
void connexion()
|
||||
{ VARCHAR uid[50];
|
||||
char login[20];
|
||||
char passwd[20];
|
||||
printf("\n");
|
||||
strcpy(uid.arr,"palafour");
|
||||
strcat(uid.arr,"/");
|
||||
strcat(uid.arr,"1s;ph;;1");
|
||||
strcat(uid.arr,"@kirov");
|
||||
uid.len=strlen(uid.arr);
|
||||
EXEC SQL CONNECT :uid;
|
||||
if (sqlca.sqlcode==0)
|
||||
printf(" Connexion réussie avec succès.\n\n");
|
||||
else
|
||||
{
|
||||
printf ("Problème à la connexion.\n\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
void deconnexion(int validation)
|
||||
{
|
||||
if (validation == 1)
|
||||
{
|
||||
EXEC SQL COMMIT WORK RELEASE;
|
||||
}
|
||||
else
|
||||
{
|
||||
EXEC SQL ROLLBACK WORK RELEASE;
|
||||
}
|
||||
printf("\nDéconnexion sans problème.\n");
|
||||
}
|
||||
|
||||
|
||||
void sql_error(char *msg)
|
||||
{
|
||||
char err_msg[128];
|
||||
long buf_len, msg_len;
|
||||
EXEC SQL WHENEVER SQLERROR CONTINUE;
|
||||
printf("%s\n", msg);
|
||||
buf_len = sizeof (err_msg);
|
||||
sqlglm(err_msg, &buf_len, &msg_len);
|
||||
if (msg_len > buf_len)
|
||||
msg_len = buf_len;
|
||||
printf("%.*s\n", msg_len, err_msg);
|
||||
deconnexion(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
void traitErreur(char *msg)
|
||||
{
|
||||
EXEC SQL WHENEVER SQLERROR CONTINUE;
|
||||
printf("%s\n", msg);
|
||||
deconnexion(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
varchar vnom[20];
|
||||
varchar vprenom[20];
|
||||
varchar vhopital[20];
|
||||
char vidhopital[6];
|
||||
int fini;
|
||||
int fin=1;
|
||||
int vnbnom;
|
||||
int vnbhopit;
|
||||
int nb=1;
|
||||
|
||||
EXEC SQL WHENEVER SQLERROR DO sql_error("Oracle error\n");
|
||||
printf("\n Appel de la fonction connexion");
|
||||
connexion();
|
||||
printf("\n Appel de la fonction deconnexion");
|
||||
|
||||
/*----------------------------------lecture----------------------------*/
|
||||
EXEC SQL WHENEVER SQLERROR DO sql_error("Oracle error\n");
|
||||
|
||||
/* SELECT p.Nom, p.Prenom, h.Nom FROM PERSONNEL p, HOPITAL h WHERE h.id_hopital = p.id_hopital and p.id_personnel='PE01'; */
|
||||
/* printf("\nUn exemple PE01 \n");*/
|
||||
|
||||
EXEC SQL SELECT p.Nom, p.Prenom, h.Nom INTO :vnom, :vprenom, :vhopital FROM PERSONNEL p, HOPITAL h WHERE h.id_hopital = p.id_hopital and p.id_personnel='PE01';
|
||||
|
||||
vnom.len=strlen(vnom.arr);
|
||||
vprenom.len=strlen(vprenom.arr);
|
||||
vhopital.len=strlen(vhopital.arr);
|
||||
|
||||
printf("\n TEST pour PE01 : Nom : %.*s prenom : %.*s hopital : %.*s \n", vnom.len, vnom.arr, vprenom.len, vprenom.arr, vhopital.len,vhopital.arr);
|
||||
|
||||
printf("\n Affichage les hopitaux \n");
|
||||
|
||||
/* SELECT COUNT(h.Nom) FROM HOPITAL h */
|
||||
EXEC SQL SELECT COUNT(h.Nom) INTO :vnbhopit FROM HOPITAL h;
|
||||
printf("\nNombre d'hopitaux est %d\n",vnbhopit);
|
||||
|
||||
EXEC SQL DECLARE hopitaux CURSOR FOR SELECT Nom, id_hopital FROM HOPITAL ORDER by Nom;
|
||||
EXEC SQL OPEN hopitaux;
|
||||
|
||||
EXEC SQL FETCH hopitaux INTO :vhopital, :vidhopital;
|
||||
if (sqlca.sqlcode == 1403) {fin = 0;}
|
||||
while (fin!=0)
|
||||
{
|
||||
vhopital.len=strlen(vhopital.arr);
|
||||
printf("\n Affichage des personnels de l'hopital %.*s : \n",vhopital.len,vhopital.arr);
|
||||
|
||||
/* SELECT COUNT(p.Nom) FROM PERSONNEL WHERE h.id_hopital = p.id_hopital; */
|
||||
EXEC SQL SELECT COUNT(Nom) INTO :vnbnom FROM PERSONNEL WHERE id_hopital = :vidhopital;
|
||||
printf("\nNombre de personnel de l'hopital %.*s est %d\n",vhopital.len,vhopital.arr, vnbnom);
|
||||
|
||||
/* SELECT p.Nom, p.Prenom FROM PERSONNEL p, WHERE h.id_hopital = p.id_hopital ORDER by p.prenom ; */
|
||||
EXEC SQL DECLARE personnels CURSOR FOR SELECT Nom, Prenom FROM PERSONNEL WHERE id_hopital = :vidhopital ORDER by prenom;
|
||||
|
||||
EXEC SQL OPEN personnels;
|
||||
fini=1;
|
||||
EXEC SQL FETCH personnels INTO :vnom, :vprenom;
|
||||
if (sqlca.sqlcode == 1403) {fini = 0;}
|
||||
|
||||
while (fini!=0)
|
||||
{
|
||||
vnom.len=strlen(vnom.arr);
|
||||
vprenom.len=strlen(vprenom.arr);
|
||||
|
||||
printf("%d) Nom : %.*s Prenom : %.*s \n", nb, vnom.len, vnom.arr, vprenom.len, vprenom.arr);
|
||||
nb++;
|
||||
EXEC SQL FETCH personnels INTO :vnom, :vprenom;
|
||||
if (sqlca.sqlcode == 1403) {fini = 0;}
|
||||
}
|
||||
EXEC SQL CLOSE personnels;
|
||||
|
||||
EXEC SQL FETCH hopitaux INTO :vhopital, :vidhopital;
|
||||
if (sqlca.sqlcode == 1403) {fin = 0;}
|
||||
}
|
||||
printf(" Fini \n");
|
||||
EXEC SQL CLOSE hopitaux;
|
||||
|
||||
deconnexion(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,142 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define size_t long
|
||||
|
||||
EXEC SQL INCLUDE SQLCA.H;
|
||||
EXEC SQL INCLUDE SQLDA.H;
|
||||
EXEC SQL INCLUDE ORACA.H;
|
||||
|
||||
|
||||
void connexion()
|
||||
{ VARCHAR uid[50];
|
||||
char login[20];
|
||||
char passwd[20];
|
||||
printf("\n");
|
||||
strcpy(uid.arr,"palafour");
|
||||
strcat(uid.arr,"/");
|
||||
strcat(uid.arr,"1s;ph;;1");
|
||||
strcat(uid.arr,"@kirov");
|
||||
uid.len=strlen(uid.arr);
|
||||
EXEC SQL CONNECT :uid;
|
||||
if (sqlca.sqlcode==0)
|
||||
printf(" Connexion réussie avec succès.\n\n");
|
||||
else
|
||||
{
|
||||
printf ("Problème à la connexion.\n\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
void deconnexion(int validation)
|
||||
{
|
||||
if (validation == 1)
|
||||
{
|
||||
EXEC SQL COMMIT WORK RELEASE;
|
||||
}
|
||||
else
|
||||
{
|
||||
EXEC SQL ROLLBACK WORK RELEASE;
|
||||
}
|
||||
printf("\nDéconnexion sans problème.\n");
|
||||
}
|
||||
|
||||
|
||||
void sql_error(char *msg)
|
||||
{
|
||||
char err_msg[128];
|
||||
long buf_len, msg_len;
|
||||
EXEC SQL WHENEVER SQLERROR CONTINUE;
|
||||
printf("%s\n", msg);
|
||||
buf_len = sizeof (err_msg);
|
||||
sqlglm(err_msg, &buf_len, &msg_len);
|
||||
if (msg_len > buf_len)
|
||||
msg_len = buf_len;
|
||||
printf("%.*s\n", msg_len, err_msg);
|
||||
deconnexion(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
void traitErreur(char *msg)
|
||||
{
|
||||
EXEC SQL WHENEVER SQLERROR CONTINUE;
|
||||
printf("%s\n", msg);
|
||||
deconnexion(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
char vidperso[20];
|
||||
char vidfonction[20];
|
||||
char vidhopital[6];
|
||||
VARCHAR vnom[20];
|
||||
VARCHAR vprenom[20];
|
||||
char eidperso[20];
|
||||
char eidfonction[20];
|
||||
char eidhopital[6];
|
||||
VARCHAR enom[20];
|
||||
VARCHAR eprenom[20];
|
||||
int nbhopital=0;
|
||||
int nbfonction=0;
|
||||
int nbperso=1;
|
||||
|
||||
|
||||
EXEC SQL WHENEVER SQLERROR DO sql_error("Oracle error\n");
|
||||
printf("\n Appel de la fonction connexion");
|
||||
connexion();
|
||||
printf("\n Appel de la fonction deconnexion");
|
||||
|
||||
/*----------------------------------lecture----------------------------*/
|
||||
EXEC SQL WHENEVER SQLERROR DO sql_error("Oracle error\n");
|
||||
|
||||
printf("Saisir un nouveau personnel \n");
|
||||
printf("Entrer son nom : ");
|
||||
scanf("%s",vnom.arr);
|
||||
vnom.len=strlen(vnom.arr);
|
||||
printf("Entrer son prenom : ");
|
||||
scanf("%s",vprenom.arr);
|
||||
vprenom.len=strlen(vprenom.arr);
|
||||
|
||||
do{
|
||||
printf("Entrer son id hopital : ");
|
||||
scanf("%s",vidhopital);
|
||||
EXEC SQL SELECT COUNT(*) INTO :nbhopital FROM HOPITAL WHERE id_hopital=:vidhopital;
|
||||
//printf("nbhopital %d\n",nbhopital);
|
||||
}
|
||||
while (nbhopital !=1);
|
||||
|
||||
do{
|
||||
printf("Entrer son id personnel : ");
|
||||
scanf("%s",vidperso);
|
||||
EXEC SQL SELECT COUNT(*) INTO :nbperso FROM PERSONNEL WHERE id_personnel=:vidperso;
|
||||
if (nbperso==1){
|
||||
printf("Ce numero de personnel existe deja\n");
|
||||
EXEC SQL SELECT * INTO :eidperso, :eidfonction, :eidhopital, :enom, :eprenom FROM PERSONNEL WHERE id_personnel=:vidperso;
|
||||
printf("ID PERSO : %s \n",eidperso);
|
||||
printf("ID FONCTION : %s \n",eidfonction);
|
||||
printf("ID HOPITAL : %s \n",eidhopital);
|
||||
printf("NOM : %s \n",enom.arr);
|
||||
printf("PRENOM : %s \n",eprenom.arr);
|
||||
}
|
||||
}
|
||||
while (nbperso !=0);
|
||||
|
||||
do{
|
||||
printf("Entrer son id fonction : ");
|
||||
scanf("%s",vidfonction);
|
||||
EXEC SQL SELECT COUNT(*) INTO :nbfonction FROM FONCTION WHERE id_fonction=:vidfonction;
|
||||
}
|
||||
while (nbfonction !=1);
|
||||
|
||||
EXEC SQL INSERT INTO PERSONNEL VALUES (:vidperso,:vidfonction,:vidhopital,:vnom,:vprenom);
|
||||
|
||||
EXEC SQL COMMIT;
|
||||
|
||||
|
||||
deconnexion(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 228 KiB |
@ -0,0 +1,312 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define size_t long
|
||||
|
||||
EXEC SQL INCLUDE SQLCA.H;
|
||||
EXEC SQL INCLUDE SQLDA.H;
|
||||
EXEC SQL INCLUDE ORACA.H;
|
||||
|
||||
void connexion()
|
||||
{ VARCHAR uid[50];
|
||||
char login[20];
|
||||
char passwd[20];
|
||||
printf("\n");
|
||||
strcpy(uid.arr,"palafour2");
|
||||
strcat(uid.arr,"/");
|
||||
strcat(uid.arr,"palafour2");
|
||||
strcat(uid.arr,"@kirov");
|
||||
uid.len=strlen(uid.arr);
|
||||
EXEC SQL CONNECT :uid;
|
||||
|
||||
if (sqlca.sqlcode==0)
|
||||
printf(" Connexion réussie avec succès.\n\n");
|
||||
else
|
||||
{
|
||||
printf ("Problème à la connexion.\n\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
void deconnexion(int validation)
|
||||
{
|
||||
if (validation == 1)
|
||||
{
|
||||
EXEC SQL COMMIT WORK RELEASE;
|
||||
}
|
||||
else
|
||||
{
|
||||
EXEC SQL ROLLBACK WORK RELEASE;
|
||||
}
|
||||
printf("\nDéconnexion sans problème.\n");
|
||||
}
|
||||
|
||||
|
||||
void sql_error(char *msg)
|
||||
{
|
||||
char err_msg[128];
|
||||
long buf_len, msg_len;
|
||||
EXEC SQL WHENEVER SQLERROR CONTINUE;
|
||||
printf("%s\n", msg);
|
||||
buf_len = sizeof (err_msg);
|
||||
sqlglm(err_msg, &buf_len, &msg_len);
|
||||
if (msg_len > buf_len)
|
||||
msg_len = buf_len;
|
||||
printf("%.*s\n", msg_len, err_msg);
|
||||
deconnexion(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
void traitErreur(char *msg)
|
||||
{
|
||||
EXEC SQL WHENEVER SQLERROR CONTINUE;
|
||||
printf("%s\n", msg);
|
||||
deconnexion(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
void saisie(void)
|
||||
{
|
||||
varchar nocl[4];
|
||||
varchar nom[80];
|
||||
varchar ville[80];
|
||||
int cp;
|
||||
|
||||
printf("Saisir une nouveau client \n");
|
||||
printf("Entrer le nom du client : ");
|
||||
scanf("%s",nom.arr);
|
||||
nom.len=strlen(nom.arr);
|
||||
printf("Entrer la ville du client : ");
|
||||
scanf("%s",ville.arr);
|
||||
ville.len=strlen(ville.arr);
|
||||
|
||||
printf("Entrer le code postal du client : ");
|
||||
scanf("%d",&cp);
|
||||
|
||||
printf("Entrer le code du client : ");
|
||||
scanf("%s",nocl.arr);
|
||||
nocl.len=strlen(nocl.arr);
|
||||
|
||||
EXEC SQL WHENEVER SQLERROR DO sql_error("Oracle error\n");
|
||||
|
||||
EXEC SQL INSERT INTO TClient2017 VALUES (:nocl,:nom,:ville,:cp);
|
||||
|
||||
EXEC SQL COMMIT;
|
||||
}
|
||||
|
||||
void modification(void){
|
||||
varchar noclchange[4];
|
||||
varchar nomnew[80];
|
||||
varchar villenew[80];
|
||||
int cpnew;
|
||||
|
||||
varchar nomold[80];
|
||||
varchar villeold[80];
|
||||
int cpold;
|
||||
|
||||
printf("Modifier un client \n");
|
||||
|
||||
printf("Entrer le code du client a modifer : ");
|
||||
scanf("%s",noclchange.arr);
|
||||
noclchange.len=strlen(noclchange.arr);
|
||||
|
||||
EXEC SQL WHENEVER SQLERROR DO sql_error("Oracle error\n");
|
||||
|
||||
EXEC SQL SELECT nom, ville, postal INTO :nomold, :villeold, :cpold FROM Tclient2017 WHERE NOCLIENT = :noclchange;
|
||||
|
||||
printf("Nom: %s \n",nomold.arr);
|
||||
printf("Ville: %s \n",villeold.arr);
|
||||
printf("CP courant du client: %d \n ",cpold);
|
||||
|
||||
printf("Modifier le nom du client : ");
|
||||
scanf("%s",nomnew.arr);
|
||||
nomnew.len=strlen(nomnew.arr);
|
||||
printf("Modifier la ville du client : ");
|
||||
scanf("%s",villenew.arr);
|
||||
villenew.len=strlen(villenew.arr);
|
||||
printf("Modifier le code postal du client : ");
|
||||
scanf("%d",&cpnew);
|
||||
|
||||
EXEC SQL UPDATE TClient2017 SET nom = :nomnew, ville = :villenew, postal = :cpnew WHERE noclient = :noclchange;
|
||||
|
||||
EXEC SQL COMMIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void suppression(void){
|
||||
|
||||
varchar noclchange[4];
|
||||
varchar nomnew[80];
|
||||
varchar villenew[80];
|
||||
int kmdeb;
|
||||
int kmfin;
|
||||
varchar noveh[4];
|
||||
varchar datedeb[30];
|
||||
varchar dateretour[30];
|
||||
int fini=1;
|
||||
|
||||
printf("Supprimer un client \n");
|
||||
|
||||
printf("Entrer le code du client a supprimer : ");
|
||||
scanf("%s",noclchange.arr);
|
||||
noclchange.len=strlen(noclchange.arr);
|
||||
|
||||
EXEC SQL DECLARE locencours CURSOR FOR SELECT noveh, datedeb, kmdeb, dateretprev FROM Tlocation2017 WHERE noclient =:noclchange ;
|
||||
|
||||
EXEC SQL DECLARE locretour CURSOR FOR SELECT noveh, datedeb, kmdeb, kmfin, dateretour FROM Tlocatretour2017 WHERE noclient =:noclchange ;
|
||||
|
||||
EXEC SQL OPEN locencours;
|
||||
|
||||
while (fini=1)
|
||||
{
|
||||
EXEC SQL FETCH locencours INTO :noveh, :datedeb, :kmdeb, :dateretour;
|
||||
printf("noveh: %s datedeb: %s kmdeb : %d date retour: %s \n",noveh.arr,datedeb.arr,kmdeb,dateretour.arr);
|
||||
if (sqlca.sqlcode == 1403) fini=0;
|
||||
}
|
||||
|
||||
printf("en retour \n");
|
||||
|
||||
EXEC SQL CLOSE locencours;
|
||||
|
||||
EXEC SQL OPEN locretour;
|
||||
|
||||
fini=1;
|
||||
while (fini=1)
|
||||
{
|
||||
EXEC SQL FETCH locretour INTO :noveh, :datedeb, :kmdeb, :kmfin, :dateretour;
|
||||
printf("noveh: %s datedeb: %s kmdeb : %d kmfin : %d date retour: %s \n",noveh.arr,datedeb.arr,kmdeb,kmfin,dateretour.arr);
|
||||
if (sqlca.sqlcode == 1403) fini=0;
|
||||
}
|
||||
|
||||
printf("Suppression en cours");
|
||||
|
||||
EXEC SQL CLOSE locretour;
|
||||
|
||||
EXEC SQL DELETE FROM Tlocation2017 WHERE noclient =:noclchange ;
|
||||
EXEC SQL DELETE FROM Tlocatretour2017 WHERE noclient =:noclchange ;
|
||||
|
||||
EXEC SQL COMMIT;
|
||||
}
|
||||
|
||||
|
||||
void afficherclient (void){
|
||||
|
||||
varchar noclient[4];
|
||||
varchar nom[80];
|
||||
varchar ville[80];
|
||||
int postal;
|
||||
int fini=1;
|
||||
|
||||
printf("Affiche les clients \n");
|
||||
|
||||
EXEC SQL DECLARE clients CURSOR FOR SELECT noclient, nom, ville, postal FROM Tclient2017;
|
||||
EXEC SQL OPEN clients;
|
||||
|
||||
while (fini=1)
|
||||
{
|
||||
EXEC SQL FETCH clients INTO :noclient, :nom, :ville, :postal;
|
||||
printf("numero client: %s nom: %s ville : %s CP: %d \n",noclient.arr,nom.arr,ville.arr,postal);
|
||||
if (sqlca.sqlcode = 1403) fini = 0;
|
||||
}
|
||||
printf(" Fini \n");
|
||||
EXEC SQL CLOSE clients;
|
||||
}
|
||||
|
||||
|
||||
void afficherlocation (void){
|
||||
|
||||
varchar nocl[4];
|
||||
varchar nom[100][10];
|
||||
|
||||
varchar noveh[5];
|
||||
|
||||
varchar immat[50][10];
|
||||
varchar datedeb[50][30];
|
||||
varchar dateretour[50][30];
|
||||
int i;
|
||||
|
||||
printf("Affiche les locations d'un client \n");
|
||||
printf("Entrer le numera du client : ");
|
||||
scanf("%s",nocl.arr);
|
||||
nocl.len=strlen(nocl.arr);
|
||||
|
||||
EXEC SQL SELECT immat, datedeb, dateretour INTO :immat, :datedeb, :dateretour FROM Tvehicule2017, Tlocatretour2017 WHERE Tlocatretour2017.nocl = :nocl and Tlocatretour2017.noveh = Tvehicule2017.noveh ;
|
||||
|
||||
printf("Il y a %d lignes selectionnees\n",sqlca.sqlerrd[2]);
|
||||
i=0;
|
||||
|
||||
while (i<sqlca.sqlerrd[2])
|
||||
{
|
||||
printf("immat : %s date retour: %s date debut : %s \n",immat[i].arr, datedeb[i].arr,dateretour[i].arr);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void afficherlocencours (void){
|
||||
|
||||
varchar noclients[4];
|
||||
varchar nom[80];
|
||||
varchar immat[10];
|
||||
varchar modele[30];
|
||||
varchar couleur[30];
|
||||
int kilometrage; // Tvehicule2017 noveh
|
||||
varchar libelle[20]; // Tcategorie2017 nocat
|
||||
varchar datedeb[20]; // Tlocatretour2017 noclient
|
||||
varchar dateretprev[20];
|
||||
int postal;
|
||||
|
||||
printf("Affiche les clients ayant une location en cours\n");
|
||||
|
||||
EXEC SQL DECLARE c CURSOR FOR SELECT noclient FROM Tlocation2017;
|
||||
|
||||
EXEC SQL OPEN c;
|
||||
EXEC SQL WHENEVER NOT FOUND goto suite;
|
||||
|
||||
while (1)
|
||||
{
|
||||
EXEC SQL FETCH c INTO :noclients;
|
||||
printf("numero client: %s nom: %s \n",noclients.arr);
|
||||
}
|
||||
suite : printf(" A FINIR \n");
|
||||
|
||||
EXEC SQL CLOSE c;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
char touche=' ';
|
||||
|
||||
EXEC SQL WHENEVER SQLERROR DO sql_error("Oracle error\n");
|
||||
printf("\n Appel de la fonction connexion");
|
||||
connexion();
|
||||
|
||||
while(touche != 'Q')
|
||||
{
|
||||
printf("\n MENU \n ");
|
||||
printf("Faites votre choix \n ");
|
||||
printf("S pour saisir un client \n ");
|
||||
printf("M pour modifier un client \n ");
|
||||
printf("E pour effacer un client \n ");
|
||||
printf("A pour afficher tous les clients \n ");
|
||||
printf("L pour afficher toutes les locations d'un client \n ");
|
||||
printf("C pour afficher toutes les clients ayant une location en cours \n ");
|
||||
printf("Q pour quitter \n ");
|
||||
scanf("%s",touche);
|
||||
|
||||
if (touche ='S') saisie();
|
||||
if (touche ='M') modification();
|
||||
if (touche ='E') suppression();
|
||||
if (touche ='A') afficherclient();
|
||||
if (touche ='L') afficherlocation();
|
||||
if (touche ='C') afficherlocencours();
|
||||
}
|
||||
|
||||
printf("\n Appel de la fonction deconnexion");
|
||||
deconnexion(1);
|
||||
return(0);
|
||||
}
|
@ -0,0 +1,420 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
EXEC SQL INCLUDE SQLCA.H;
|
||||
EXEC SQL INCLUDE SQLDA.H;
|
||||
EXEC SQL INCLUDE ORACA.H;
|
||||
|
||||
#define CLEAR system("clear")
|
||||
|
||||
/********** Constantes **********/
|
||||
#define CONTINUE 0
|
||||
#define DATE_LEN 11
|
||||
#define DEPT_LEN 3
|
||||
#define NOM_LEN 21
|
||||
#define NOT_FOUND 1403
|
||||
#define REFERENCE_LEN 5
|
||||
#define SQL_COMMIT 1
|
||||
#define SQL_ROLLBACK 0
|
||||
#define SQL_SUCCESS 0
|
||||
#define STOP 1
|
||||
#define UID_LEN 30
|
||||
#define VARCHAR_LEN 51
|
||||
|
||||
/********** Liste des fonctions **********/
|
||||
void connexion(void);
|
||||
void erreur_sql(int arret);
|
||||
void deconnexion(int validation);
|
||||
void q1(void);
|
||||
int q1bis(void);
|
||||
void q2(void);
|
||||
void q3(void);
|
||||
void q4(void);
|
||||
void q5(void);
|
||||
void q6(void);
|
||||
void q7(void);
|
||||
/*
|
||||
* Fonction de connexion à Oracle.
|
||||
*
|
||||
* Les identifiants sont rentrés en dur pour ne pas avoir à les retaper
|
||||
* à la main à chaque test, mais dans l'idéal, on demande à l'utilisateur
|
||||
* de les rentrer et on concatène les identifiants à uid.arr.
|
||||
*/
|
||||
void connexion(void) {
|
||||
VARCHAR uid[UID_LEN];
|
||||
char identifiants[UID_LEN] = "danguyen1/danguyen1@kirov";
|
||||
printf("Connexion avec les identifiants suivants : %s .\n", identifiants);
|
||||
strcpy(uid.arr, identifiants);
|
||||
uid.len = strlen(uid.arr);
|
||||
|
||||
EXEC SQL CONNECT :uid;
|
||||
if (sqlca.sqlcode == SQL_SUCCESS) {
|
||||
printf("Connexion réussie avec succès !\n\n");
|
||||
}
|
||||
else {
|
||||
printf("Connexion échouée !\n\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fonction qui affiche les code et message d'erreur SQL.
|
||||
*
|
||||
* Paramètres :
|
||||
* arret STOP(1) pour quitter, n'importe quoi pour continuer
|
||||
*/
|
||||
void erreur_sql(int arret) {
|
||||
printf("Code d'erreur : %d.\n", sqlca.sqlcode);
|
||||
printf("Message erreur : %.*s.\n", sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc);
|
||||
if (arret == STOP) {
|
||||
deconnexion(SQL_ROLLBACK);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fonction de déconnexion.
|
||||
*
|
||||
* Paramètres :
|
||||
* validation SQL_COMMIT(1) pour COMMIT, n'importe quoi pour ROLLBACK
|
||||
*/
|
||||
void deconnexion(int validation) {
|
||||
if (validation == SQL_COMMIT) {
|
||||
EXEC SQL COMMIT WORK RELEASE;
|
||||
}
|
||||
else {
|
||||
EXEC SQL ROLLBACK WORK RELEASE;
|
||||
}
|
||||
printf("Déconnexion réussie, travail %s.\n", validation == 1 ? "enregistré" : "annulé");
|
||||
}
|
||||
|
||||
/*
|
||||
* Affiche le nombre de produits contenus dans la base (utilisée dans la question 3
|
||||
* car pas d'intérêt à être utilisée toute seule).
|
||||
*
|
||||
* Retourne :
|
||||
* le nombre de produits contenus dans la base
|
||||
*/
|
||||
int q1(void) {
|
||||
int nbProd;
|
||||
EXEC SQL SELECT COUNT(*) INTO nbProd FROM TPRODUIT;
|
||||
printf("Il y a %d produits en base.\n", nbProd);
|
||||
return nbProd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Modifie un produit en affichant ses anciennes valeurs.
|
||||
*/
|
||||
void q2(void) {
|
||||
char codeRayon[REFERENCE_LEN], dateStock[DATE_LEN], nCodeRayon[REFERENCE_LEN], nDateStock[DATE_LEN], noProd[REFERENCE_LEN];
|
||||
int choix, nStock, stock;
|
||||
float nPrixV, prixV;
|
||||
VARCHAR des[VARCHAR_LEN], nDes[VARCHAR_LEN];
|
||||
|
||||
printf("Saisir numéro produit : ");
|
||||
scanf("%s%*c", noProd);
|
||||
|
||||
EXEC SQL
|
||||
SELECT des, stock, prixV, codeRayon, dateStock
|
||||
INTO :des, :stock, :prixV, :codeRayon, :dateStock
|
||||
FROM TPRODUIT
|
||||
WHERE noProd = :noProd;
|
||||
|
||||
printf("1 - Désignation : %.*s.\n", des.len, des.arr);
|
||||
printf("2 - Stock : %d.\n", stock);
|
||||
printf("3 - Prix de vente : %.2f€.\n", prixV);
|
||||
printf("4 - Code rayon : %s.\n", codeRayon);
|
||||
printf("5 - Date : %s.\n", dateStock);
|
||||
|
||||
while (choix != 9) {
|
||||
printf("Que voulez-vous modifier (9: quitter) ?\n");
|
||||
scanf("%d%*c", &choix);
|
||||
|
||||
switch (choix) {
|
||||
case 1:
|
||||
printf("Entrez la nouvelle désignation : ");
|
||||
fgets(nDes, sizeof nDes, stdin);
|
||||
if (nDes[strlen(nDes) - 1] == '\n') {
|
||||
nDes[strlen(nDes) - 1] = '\0';
|
||||
}
|
||||
EXEC SQL
|
||||
UPDATE TPRODUIT
|
||||
SET des = :nDes
|
||||
WHERE noProd = :noProd;
|
||||
if (sqlca.sqlcode < SQL_SUCCESS) {
|
||||
erreur_sql(STOP);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
printf("Entrez le nouveau stock : ");
|
||||
scanf("%d%*c", &nStock);
|
||||
EXEC SQL
|
||||
UPDATE TPRODUIT
|
||||
SET stock = :nStock
|
||||
WHERE noProd = :noProd;
|
||||
if (sqlca.sqlcode < SQL_SUCCESS) {
|
||||
erreur_sql(STOP);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
printf("Entrez le nouveau prix : ");
|
||||
scanf("%f%*c", &nPrixV);
|
||||
EXEC SQL
|
||||
UPDATE TPRODUIT
|
||||
SET prixV = :nPrixV
|
||||
WHERE noProd = :noProd;
|
||||
if (sqlca.sqlcode < SQL_SUCCESS) {
|
||||
erreur_sql(STOP);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
printf("Entrez le nouveau code rayon : ");
|
||||
scanf("%s", &nCodeRayon);
|
||||
EXEC SQL
|
||||
UPDATE TPRODUIT
|
||||
SET codeRayon = :nCodeRayon
|
||||
WHERE noProd = :noProd;
|
||||
if (sqlca.sqlcode < SQL_SUCCESS) {
|
||||
erreur_sql(STOP);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
printf("Entrez la date : ");
|
||||
scanf("%s", &nDateStock);
|
||||
EXEC SQL
|
||||
UPDATE TPRODUIT
|
||||
SET dateStock = :nDateStock
|
||||
WHERE noProd = :noProd;
|
||||
if (sqlca.sqlcode < SQL_SUCCESS) {
|
||||
erreur_sql(STOP);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("Choix inconnu.\n");
|
||||
break;
|
||||
}
|
||||
EXEC SQL COMMIT;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Affiche le nombre de produits en base et les affiche.
|
||||
*/
|
||||
void q3(void) {
|
||||
char noProd[REFERENCE_LEN], codeRayon[REFERENCE_LEN], dateStock[DATE_LEN];
|
||||
int cpt = 0, nbProd, stock;
|
||||
float prixV;
|
||||
VARCHAR des[REFERENCE_LEN1];
|
||||
|
||||
nbProd = q1bis();
|
||||
if (nbProd > 0) {
|
||||
EXEC SQL
|
||||
DECLARE cprod CURSOR FOR
|
||||
SELECT noProd, des, stock, prixV, codeRayon, dateStock
|
||||
FROM TPRODUIT;
|
||||
EXEC SQL OPEN cprod;
|
||||
EXEC SQL FETCH cprod INTO :noProd, :des, :stock, :prixV, :codeRayon, :dateStock;
|
||||
|
||||
while (sqlca.sqlcode != NOT_FOUND) {
|
||||
printf("----- Produit n°%d -----\n", ++cpt);
|
||||
printf("Numéro produit : %s.\n", noProd);
|
||||
printf("Désignation : %.*s.\n", des.len, des.arr);
|
||||
printf("Stock : %d.\n", stock);
|
||||
printf("Prix de vente : %.2f.\n", prixV);
|
||||
printf("Code rayon : %s.\n", codeRayon);
|
||||
printf("Date stock : %s.\n", dateStock);
|
||||
EXEC SQL
|
||||
FETCH cprod INTO :noProd, :des, :stock, :prixV, :codeRayon, :dateStock;
|
||||
if (sqlca.sqlcode < SQL_SUCCESS) {
|
||||
erreur_sql(STOP);
|
||||
}
|
||||
}
|
||||
EXEC SQL CLOSE cprod;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Ajoute un produit saisi.
|
||||
*/
|
||||
void q4(void) {
|
||||
char choix, noProd[REFERENCE_LEN], dateStock[DATE_LEN];
|
||||
int stock;
|
||||
float prixV;
|
||||
short indicateurDes = 0, indicateurStock = 0, indicateurPrixV = 0, indicateurCodeRayon = 0, indicateurDateStock = 0;
|
||||
VARCHAR des[VARCHAR_LEN];
|
||||
|
||||
printf("Saisir numéro produit : ");
|
||||
scanf("%s%*c", noProd);
|
||||
printf("Saisir une désignation (O/*) ? ");
|
||||
scanf("%c%*c", &choix);
|
||||
if (toUpper(choix) == 'O') {
|
||||
printf("Saisir la désignation : ");
|
||||
fgets(des, sizeof des, stdin);
|
||||
if (des[strlen(des) - 1] == '\n') {
|
||||
des[strlen(des) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
else {
|
||||
indicateurDes = -1;
|
||||
}
|
||||
|
||||
printf("Saisir un stock (O/*) ? ");
|
||||
scanf("%c%*c", &choix);
|
||||
if (toUpper(choix) == 'O') {
|
||||
printf("Saisir le stock : ");
|
||||
scanf("%d%*c", &stock);
|
||||
}
|
||||
else {
|
||||
indicateurStock = -1;
|
||||
}
|
||||
|
||||
printf("Saisir un prix de vente : ");
|
||||
scanf("%c%*c", &choix);
|
||||
if (toUpper(choix) == 'O') {
|
||||
printf("Saisir le prix de vente : ");
|
||||
scanf("%f%*c", &prixV);
|
||||
}
|
||||
else {
|
||||
indicateurPrixV = -1;
|
||||
}
|
||||
|
||||
printf("Saisir un code rayon (O/*) ? ");
|
||||
scanf("%c%*c", &choix);
|
||||
if (toUpper(choix) == 'O') {
|
||||
printf("Saisir le code rayon : ");
|
||||
scanf("%d%*c", codeRayon);
|
||||
}
|
||||
else {
|
||||
indicateurCodeRayon = -1;
|
||||
}
|
||||
|
||||
if (indicateurStock == 0) {
|
||||
EXEC SQL
|
||||
SELECT SYSDATE
|
||||
INTO :dateStock
|
||||
FROM DUAL;
|
||||
|
||||
}
|
||||
else {
|
||||
indicateurDateStock = -1;
|
||||
}
|
||||
|
||||
EXEC SQL
|
||||
INSERT INTO TPRODUIT
|
||||
VALUES(
|
||||
:noProd,
|
||||
:des INDICATOR :indicateurDes,
|
||||
:stock INDICATOR :indicateurStock,
|
||||
:codeRayon INDICATOR :indicateurCodeRayon,
|
||||
:dateStock INDICATOR :indicateurDateStock
|
||||
);
|
||||
|
||||
EXEC SQL COMMIT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Affiche les produits d'un fournisseur saisi.
|
||||
*/
|
||||
void q5(void) {
|
||||
char noProd[REFERENCE_LEN], refFourn[REFERENCE_LEN];
|
||||
printf("Saisir référence fournisseur : ");
|
||||
scanf("%s%*c", refFourn);
|
||||
|
||||
EXEC SQL
|
||||
DECLARE cprod CURSOR FOR
|
||||
SELECT noProd
|
||||
FROM TPRODUITFOURN
|
||||
WHERE pf.refFourn = :refFourn;
|
||||
|
||||
EXEC SQL OPEN cprod;
|
||||
|
||||
EXEC SQL FETCH cprod INTO :noProd;
|
||||
if (sqlca.sqlcode == NOT_FOUND) {
|
||||
printf("Aucun produit trouvé !\n");
|
||||
}
|
||||
|
||||
printf("Liste des numéros de produits pour ce fournisseur :\n");
|
||||
while (sqlca.sqlcode != NOT_FOUND) {
|
||||
printf("\t%s\n", noProd);
|
||||
EXEC SQL FETCH cprod INTO :noProd;
|
||||
|
||||
}
|
||||
|
||||
EXEC SQL
|
||||
CLOSE cprod;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enregistre un fournisseur saisi.
|
||||
*/
|
||||
void q6(void) {
|
||||
char refFourn[REFERENCE_LEN], dept[DEPT_LEN];
|
||||
VARCHAR nom[NOM_LEN];
|
||||
|
||||
printf("Saisir la référence fournisseur : ");
|
||||
scanf("%s%*c", refFourn);
|
||||
printf("Saisir le département : ");
|
||||
scanf("%s%*c", dept);
|
||||
printf("Saisir le nom du fournisseur : ");
|
||||
fgets(nom, sizeof nom, stdin);
|
||||
if (nom[strlen(nom) - 1] == '\n') {
|
||||
nom[strlen(nom) - 1] = '\0';
|
||||
}
|
||||
|
||||
EXEC SQL
|
||||
INSERT INTO TFOURNISSEUR
|
||||
VALUES(:refFourn, :nom, :dept);
|
||||
|
||||
EXEC SQL COMMIT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Supprime un fournisseur en prenant le soin de supprimer ses produits de la table de liaison.
|
||||
*/
|
||||
void q7(void) {
|
||||
char refFourn[REFERENCE_LEN];
|
||||
|
||||
printf("Saisir la référence du fournisseur à supprimer : ");
|
||||
scanf("%s%*c", refFourn);
|
||||
|
||||
EXEC SQL
|
||||
DELETE FROM TPRODUITFOURN
|
||||
WHERE refFourn = :refFourn;
|
||||
|
||||
EXEC SQL
|
||||
DELETE FROM TFOURNISSEUR
|
||||
WHERE refFourn = :refFourn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fonction principale.
|
||||
*
|
||||
* Paramètres :
|
||||
* argc Le nombre d'arguments
|
||||
* argv Le tableau d'arguments
|
||||
*
|
||||
* Retourne :
|
||||
* le code de retour défini dans stdlib.h
|
||||
* (EXIT_SUCCESS = 0)
|
||||
*/
|
||||
int main(int argc, char const *argv[]) {
|
||||
int validation;
|
||||
|
||||
CLEAR;
|
||||
|
||||
connexion();
|
||||
|
||||
EXEC SQL
|
||||
WHENEVER SQLERROR
|
||||
DO erreur_sql(STOP);
|
||||
|
||||
// qX();
|
||||
|
||||
printf("Enregistrer le travail ? (1 = oui, * = non)\n");
|
||||
scanf("%d%*c", &validation);
|
||||
deconnexion(validation);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -0,0 +1,174 @@
|
||||
\documentclass[a4paper,11pt]{article}
|
||||
|
||||
\usepackage[utf8x]{inputenc}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage[french]{babel}
|
||||
\usepackage[a4paper,hmargin=20mm,vmargin=30mm]{geometry}%\usepackage{fullpage}
|
||||
\usepackage{url}
|
||||
\usepackage{comment}
|
||||
\usepackage{fancyhdr}% fancy header
|
||||
\usepackage{multirow}
|
||||
\usepackage{slashbox}
|
||||
|
||||
\usepackage{color, colortbl}
|
||||
\definecolor{Gray}{gray}{0.9}
|
||||
\usepackage{adjustbox}
|
||||
\usepackage{slashbox}
|
||||
%\usepackage{times}
|
||||
\usepackage{tikz,pgflibraryarrows,pgffor,pgflibrarysnakes}
|
||||
\usetikzlibrary{decorations.pathreplacing}
|
||||
|
||||
\usepackage{pdfpages}
|
||||
|
||||
\usepackage{fancyvrb}
|
||||
|
||||
\fancypagestyle{monstyle}{
|
||||
%\fancyhead{}
|
||||
\renewcommand{\headrulewidth}{1pt}
|
||||
%% %\renewcommand{\footrulewidth}{0.4pt}
|
||||
|
||||
% \fancyhead[LE]{\slshape \thepage/ \pageref{LastPage}}
|
||||
%% \fancyhead[RO]{\slshape \thepage/ \pageref{LastPage}}
|
||||
|
||||
|
||||
%\fancyhf{}
|
||||
%\fancyhead[LE]{\slshape LE}
|
||||
%\fancyhead[CE]{\slshape CE}
|
||||
%\fancyhead[RE]{\slshape RE}
|
||||
|
||||
\fancyhead[LO]{\bfseries 2018-2019 BD PLS/SQL\rightmark}
|
||||
%\fancyhead[CO]{\slshape APF}
|
||||
\fancyhead[RO]{\bfseries ~\leftmark }
|
||||
|
||||
%% %\fancyfoot{}
|
||||
% \fancyfoot[LE,RO]{}
|
||||
\fancyfoot[CO,CE]{}%\slshape\thepage/\pageref{LastPage}}
|
||||
%% %\fancyfoot[LO,RE]{\small\slshape \ddmmyyyydate version du \today}
|
||||
|
||||
}
|
||||
|
||||
% \pagestyle{fancy}
|
||||
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amsthm}
|
||||
|
||||
|
||||
|
||||
\theoremstyle{definition}
|
||||
\newtheorem{exercice}{Exercice}
|
||||
|
||||
\pagestyle{monstyle}
|
||||
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amsthm}
|
||||
|
||||
\newcommand{\code}[1]{\texttt{#1}}
|
||||
|
||||
\usepackage{boxedminipage}
|
||||
\usepackage{setspace}
|
||||
|
||||
|
||||
\newsavebox\svbx
|
||||
\newif\ifcache
|
||||
\long\def\cache#1{\ \newline
|
||||
\setbox\svbx=\vbox{\leavevmode \newline \begin{spacing}{1}#1\end{spacing}}
|
||||
\smallskip\par\noindent
|
||||
\begin{boxedminipage}{\linewidth}
|
||||
\ifcache
|
||||
\leavevmode\hrule height 0pt\vskip \ht\svbx\hrule height 0pt
|
||||
\else \unvbox\svbx
|
||||
\fi
|
||||
\end{boxedminipage}
|
||||
\par\smallskip}
|
||||
|
||||
|
||||
\cachefalse % version prof
|
||||
%\cachetrue % version etudiant
|
||||
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
||||
\section*{NBA}
|
||||
|
||||
\begin{verbatim}
|
||||
|
||||
CREATE TABLE JOUEUR(id_joueur CHAR(6) PRIMARY KEY,
|
||||
Nom VARCHAR2(20),
|
||||
Prenom VARCHAR2(20),
|
||||
Date_de_naissance DATE,
|
||||
Taille NUMBER,
|
||||
Poste char(2) constraint c_poste CHECK (Poste IN('PG','SG','SF','PF','C')));
|
||||
|
||||
CREATE TABLE EQUIPE(id_equipe CHAR(6) PRIMARY KEY,
|
||||
Nom VARCHAR2(20),
|
||||
Ville VARCHAR2(20),
|
||||
Conference VARCHAR2(5) constraint c_conf check (Conference in('Est','Ouest')),
|
||||
Date_creation DATE);
|
||||
|
||||
CREATE TABLE GAME(id_game CHAR(6) PRIMARY KEY,
|
||||
Date_game DATE,
|
||||
id_equipe_domicile CHAR(6) references EQUIPE,
|
||||
id_equipe_exterieur CHAR(6) references EQUIPE,
|
||||
Ville VARCHAR2(20),
|
||||
Categorie char(7) constraint c_type check (Categorie in('Amical','Saison','Playoff','Allstar')),
|
||||
Score_domicile NUMBER,
|
||||
Score_exterieur NUMBER,
|
||||
Prolongation NUMBER);
|
||||
|
||||
CREATE TABLE JOUE(id_joueur CHAR(6) references JOUEUR,
|
||||
id_game CHAR(6) references GAME,
|
||||
Points NUMBER,
|
||||
Rebonds NUMBER,
|
||||
Interceptions NUMBER,
|
||||
Contres NUMBER,
|
||||
Passes NUMBER,
|
||||
Balles_perdues NUMBER,
|
||||
Fautes NUMBER,
|
||||
PRIMARY KEY(id_joueur,id_game));
|
||||
|
||||
|
||||
CREATE TABLE APPARTIENT(id_contrat CHAR(6) PRIMARY KEY,
|
||||
id_joueur CHAR(6) references JOUEUR,
|
||||
id_equipe CHAR(6) references EQUIPE,
|
||||
Date_debut DATE,
|
||||
Date_fin DATE,
|
||||
Salaire_jour NUMBER);
|
||||
\end{verbatim}
|
||||
\newpage
|
||||
|
||||
\subsection*{HOPITAL}
|
||||
|
||||
\begin{verbatim}
|
||||
|
||||
CREATE TABLE FONCTION(id_fonction CHAR(6) PRIMARY KEY,
|
||||
Designation VARCHAR(20),
|
||||
Salaire NUMBER);
|
||||
|
||||
CREATE TABLE HOPITAL(id_hopital CHAR(6) PRIMARY KEY,
|
||||
Nom VARCHAR(20),
|
||||
Ville VARCHAR(20),
|
||||
Date_creation DATE);
|
||||
|
||||
|
||||
CREATE TABLE PATIENT(id_patient CHAR(6) PRIMARY KEY,
|
||||
Nom VARCHAR(20),
|
||||
Prenom VARCHAR(20),
|
||||
Date_naissance DATE);
|
||||
|
||||
CREATE TABLE PERSONNEL(id_personnel CHAR(6) PRIMARY KEY,
|
||||
id_fonction CHAR(6) references FONCTION,
|
||||
id_hopital CHAR(6) references HOPITAL,
|
||||
Nom VARCHAR(20),
|
||||
Prenom VARCHAR(20));
|
||||
|
||||
|
||||
CREATE TABLE AFFECTATION(id_contrat CHAR(6) PRIMARY KEY,
|
||||
id_personnel CHAR(6) references PERSONNEL,
|
||||
id_patient CHAR(6) references PATIENT,
|
||||
Date_debut DATE,
|
||||
Date_fin DATE);
|
||||
\end{verbatim}
|
||||
|
||||
|
||||
\end{document}
|
@ -0,0 +1,68 @@
|
||||
DROP TABLE PERSONNEL cascade constraints;
|
||||
DROP TABLE AFFECTATION ;
|
||||
|
||||
DROP TABLE FONCTION cascade constraints;
|
||||
DROP TABLE PATIENT cascade constraints;
|
||||
DROP TABLE HOPITAL cascade constraints;
|
||||
|
||||
CREATE TABLE FONCTION(id_fonction CHAR(6) PRIMARY KEY,
|
||||
Designation VARCHAR(20),
|
||||
Salaire NUMBER);
|
||||
|
||||
CREATE TABLE HOPITAL(id_hopital CHAR(6) PRIMARY KEY,
|
||||
Nom VARCHAR(20),
|
||||
Ville VARCHAR(20),
|
||||
Date_creation DATE);
|
||||
|
||||
|
||||
CREATE TABLE PATIENT(id_patient CHAR(6) PRIMARY KEY,
|
||||
Nom VARCHAR(20),
|
||||
Prenom VARCHAR(20),
|
||||
Date_naissance DATE);
|
||||
|
||||
CREATE TABLE PERSONNEL(id_personnel CHAR(6) PRIMARY KEY,
|
||||
id_fonction CHAR(6) references FONCTION,
|
||||
id_hopital CHAR(6) references HOPITAL,
|
||||
Nom VARCHAR(20),
|
||||
Prenom VARCHAR(20));
|
||||
|
||||
|
||||
CREATE TABLE AFFECTATION(id_contrat CHAR(6) PRIMARY KEY,
|
||||
id_personnel CHAR(6) references PERSONNEL,
|
||||
id_patient CHAR(6) references PATIENT,
|
||||
Date_debut DATE,
|
||||
Date_fin DATE);
|
||||
|
||||
insert into HOPITAL values ('H01','CHU G MONPIED','CLERMONT','01-Jan-1980');
|
||||
insert into HOPITAL values ('H02','CHU ESTAING','CLERMONT','01-Jan-2010');
|
||||
insert into HOPITAL values ('H03','Chataigneraie','BEAUMONT','01-Jan-2000');
|
||||
|
||||
insert into FONCTION values ('F01','Docteur',8000);
|
||||
insert into FONCTION values ('F02','Psy',11000);
|
||||
insert into FONCTION values ('F03','ORL',10000);
|
||||
|
||||
insert into PERSONNEL values ('PE01','F03','H03','Who','John');
|
||||
insert into PERSONNEL values ('PE02','F02','H01','Jekyll','Henry');
|
||||
insert into PERSONNEL values ('PE03','F01','H02','Watson','James');
|
||||
insert into PERSONNEL values ('PE04','F02','H03','Palmer','Jimmy');
|
||||
insert into PERSONNEL values ('PE05','F01','H01','Mallard','Donald');
|
||||
insert into PERSONNEL values ('PE06','F03','H02','Blacke','Penelope');
|
||||
|
||||
insert into PATIENT values ('PA01','Marley','Bob','04-Apr-2001');
|
||||
insert into PATIENT values ('PA02','Hendrix','Jimmy','04-Apr-1998');
|
||||
insert into PATIENT values ('PA03','Dupont','Paul','04-Apr-1990');
|
||||
insert into PATIENT values ('PA04','Springsteen','Bruce','24-Apr-1990');
|
||||
insert into PATIENT values ('PA05','Jackson','Michael','14-Apr-1990');
|
||||
insert into PATIENT values ('PA06','Georges','Paul','04-Apr-1991');
|
||||
|
||||
insert into AFFECTATION values ('A01','PE01','PA01','04-Jan-1980',NULL);
|
||||
insert into AFFECTATION values ('A02','PE02','PA02','04-Jan-1981',NULL);
|
||||
insert into AFFECTATION values ('A03','PE03','PA03','04-Jan-1981','04-Jan-2010');
|
||||
insert into AFFECTATION values ('A04','PE04','PA04','04-Jan-1981','04-Jan-2010');
|
||||
insert into AFFECTATION values ('A05','PE05','PA05','04-Jan-1981','04-Jan-2010');
|
||||
insert into AFFECTATION values ('A06','PE06','PA06','04-Jan-1981','04-Jan-2010');
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,48 @@
|
||||
@nba-setup.sql;
|
||||
|
||||
DROP TABLE tligne ;
|
||||
CREATE TABLE tligne (ligne varchar2(100)) ;
|
||||
|
||||
set echo off;
|
||||
set verify off;
|
||||
set feedback off;
|
||||
|
||||
variable vidjoueur char(4)
|
||||
prompt Entrer la reference du joueur :
|
||||
accept vidjoueur
|
||||
|
||||
DECLARE
|
||||
dmaxpoint number;
|
||||
dnbjoueur number;
|
||||
didjoueur char(4);
|
||||
|
||||
BEGIN
|
||||
|
||||
SELECT count(Nom) INTO dnbjoueur FROM JOUEUR
|
||||
WHERE id_joueur ='&vidjoueur';
|
||||
|
||||
if dnbjoueur != 0 then
|
||||
|
||||
SELECT max(points) INTO dmaxpoint FROM JOUE
|
||||
WHERE id_joueur ='&vidjoueur';
|
||||
|
||||
INSERT INTO tligne VALUES ('Le maximum de point du joueur '||'&vidjoueur'||' est '||to_char(dmaxpoint));
|
||||
ELSE
|
||||
INSERT INTO tligne VALUES('AVEC COUNT : Joueur inconnu');
|
||||
end if;
|
||||
|
||||
SELECT id_joueur INTO didjoueur FROM JOUE
|
||||
WHERE id_joueur ='&vidjoueur';
|
||||
|
||||
|
||||
EXCEPTION
|
||||
when no_data_found then
|
||||
INSERT INTO tligne VALUES('AVEC EXCEPTION : Joueur n a pas fait de match');
|
||||
end ;
|
||||
.
|
||||
/
|
||||
|
||||
SELECT * FROM tligne ;
|
||||
set verify on;
|
||||
set feedback on;
|
||||
set echo on;
|
@ -0,0 +1,41 @@
|
||||
@nba-setup.sql;
|
||||
|
||||
DROP TABLE tligne ;
|
||||
CREATE TABLE tligne (ligne varchar2(100)) ;
|
||||
|
||||
set echo off;
|
||||
set verify off;
|
||||
set feedback off;
|
||||
|
||||
DECLARE
|
||||
dnom varchar2(20);
|
||||
dprenom varchar2(20);
|
||||
ddate date;
|
||||
dnomequipe varchar2(20);
|
||||
|
||||
CURSOR c IS SELECT j.Nom, j.Prenom, j.Date_de_naissance, e.Nom FROM JOUEUR j, APPARTIENT a, EQUIPE e
|
||||
WHERE a.id_joueur = j.id_joueur and e.id_equipe = a.id_equipe and a.Date_fin is NULL
|
||||
Order by Date_de_naissance;
|
||||
|
||||
|
||||
BEGIN
|
||||
OPEN c;
|
||||
|
||||
INSERT INTO tligne VALUES ('Nom Prenom Date de naissance Nom Equipe Actuelle');
|
||||
FETCH c INTO dnom, dprenom, ddate, dnomequipe;
|
||||
|
||||
WHILE c%found
|
||||
LOOP
|
||||
INSERT INTO tligne VALUES (dnom||' '||dprenom||' '||to_char(ddate)||' '||dnomequipe);
|
||||
FETCH c INTO dnom, dprenom, ddate, dnomequipe;
|
||||
END LOOP;
|
||||
|
||||
CLOSE C;
|
||||
END;
|
||||
.
|
||||
/
|
||||
|
||||
SELECT * FROM tligne ;
|
||||
set verify on;
|
||||
set feedback on;
|
||||
set echo on;
|
@ -0,0 +1,72 @@
|
||||
@nba-setup.sql;
|
||||
|
||||
DROP TABLE tligne ;
|
||||
CREATE TABLE tligne (ligne varchar2(100)) ;
|
||||
|
||||
set echo off;
|
||||
set verify off;
|
||||
set feedback off;
|
||||
|
||||
variable vannee number
|
||||
prompt Entrer une annee :
|
||||
accept vannee
|
||||
|
||||
DECLARE
|
||||
dnom varchar2(20);
|
||||
dprenom varchar2(20);
|
||||
dposte char(2);
|
||||
dnomequipe varchar2(20);
|
||||
|
||||
CURSOR Cest IS SELECT j.Nom, j.Prenom, j.Poste, e.Nom FROM JOUEUR j,
|
||||
APPARTIENT a, EQUIPE e WHERE a.id_joueur = j.id_joueur and e.id_equipe
|
||||
= a.id_equipe and e.conference='Est' and j.id_joueur in (SELECT
|
||||
id_joueur FROM JOUE je, GAME g where g.Categorie='Allstar' and
|
||||
g.id_game=je.id_game);
|
||||
|
||||
CURSOR Couest IS SELECT j.Nom, j.Prenom, j.Poste, e.Nom FROM JOUEUR j,
|
||||
APPARTIENT a, EQUIPE e WHERE a.id_joueur = j.id_joueur and e.id_equipe
|
||||
= a.id_equipe and e.conference='Ouest' and j.id_joueur in (SELECT
|
||||
id_joueur FROM JOUE je, GAME g where g.Categorie='Allstar' and
|
||||
g.id_game=je.id_game);
|
||||
|
||||
BEGIN
|
||||
|
||||
INSERT INTO tligne VALUES ('ALLSTAR GAME'||'&vannee');
|
||||
INSERT INTO tligne VALUES ('Conference Est');
|
||||
|
||||
OPEN Cest;
|
||||
|
||||
INSERT INTO tligne VALUES ('Nom Prenom Poste Nom Equipe Actuelle');
|
||||
FETCH Cest INTO dnom, dprenom, dposte, dnomequipe;
|
||||
|
||||
WHILE Cest%found
|
||||
LOOP
|
||||
INSERT INTO tligne VALUES (dnom||' '||dprenom||' '||dposte||' '||dnomequipe);
|
||||
FETCH Cest INTO dnom, dprenom, dposte, dnomequipe;
|
||||
END LOOP;
|
||||
|
||||
CLOSE Cest;
|
||||
|
||||
INSERT INTO tligne VALUES ('Conference Ouest');
|
||||
|
||||
OPEN Couest;
|
||||
|
||||
INSERT INTO tligne VALUES ('Nom Prenom Poste Nom Equipe Actuelle');
|
||||
|
||||
FETCH Couest INTO dnom, dprenom, dposte, dnomequipe;
|
||||
WHILE Couest%found
|
||||
LOOP
|
||||
INSERT INTO tligne VALUES (dnom||' '||dprenom||' '||dposte||' '||dnomequipe);
|
||||
FETCH Couest INTO dnom, dprenom, dposte, dnomequipe;
|
||||
END LOOP;
|
||||
|
||||
CLOSE Couest;
|
||||
|
||||
END;
|
||||
.
|
||||
/
|
||||
|
||||
SELECT * FROM tligne ;
|
||||
set verify on;
|
||||
set feedback on;
|
||||
set echo on;
|
@ -0,0 +1,88 @@
|
||||
DROP TABLE JOUE;
|
||||
DROP TABLE GAME;
|
||||
DROP TABLE APPARTIENT cascade constraints;
|
||||
DROP TABLE JOUEUR cascade constraints;
|
||||
DROP TABLE EQUIPE cascade constraints;
|
||||
|
||||
CREATE TABLE JOUEUR(id_joueur CHAR(6) PRIMARY KEY,
|
||||
Nom VARCHAR2(20),
|
||||
Prenom VARCHAR2(20),
|
||||
Date_de_naissance DATE,
|
||||
Taille NUMBER,
|
||||
Poste char(2) constraint c_poste CHECK (Poste IN('PG','SG','SF','PF','C')));
|
||||
|
||||
CREATE TABLE EQUIPE(id_equipe CHAR(6) PRIMARY KEY,
|
||||
Nom VARCHAR2(20),
|
||||
Ville VARCHAR2(20),
|
||||
Conference VARCHAR2(5) constraint c_conf check (Conference in('Est','Ouest')),
|
||||
Date_creation DATE);
|
||||
|
||||
CREATE TABLE GAME(id_game CHAR(6) PRIMARY KEY,
|
||||
Date_game DATE,
|
||||
id_equipe_domicile CHAR(6) references EQUIPE,
|
||||
id_equipe_exterieur CHAR(6) references EQUIPE,
|
||||
Ville VARCHAR2(20),
|
||||
Categorie char(7) constraint c_type check (Categorie in('Amical','Saison','Playoff','Allstar')),
|
||||
Score_domicile NUMBER,
|
||||
Score_exterieur NUMBER,
|
||||
Prolongation NUMBER);
|
||||
|
||||
CREATE TABLE JOUE(id_joueur CHAR(6) references JOUEUR,
|
||||
id_game CHAR(6) references GAME,
|
||||
Points NUMBER,
|
||||
Rebonds NUMBER,
|
||||
Interceptions NUMBER,
|
||||
Contres NUMBER,
|
||||
Passes NUMBER,
|
||||
Balles_perdues NUMBER,
|
||||
Fautes NUMBER,
|
||||
PRIMARY KEY(id_joueur,id_game));
|
||||
|
||||
|
||||
CREATE TABLE APPARTIENT(id_contrat CHAR(6) PRIMARY KEY,
|
||||
id_joueur CHAR(6) references JOUEUR,
|
||||
id_equipe CHAR(6) references EQUIPE,
|
||||
Date_debut DATE,
|
||||
Date_fin DATE,
|
||||
Salaire_jour NUMBER);
|
||||
|
||||
insert into JOUEUR values ('J00001','Jordan','Michael','01-Jan-1980','193','SF');
|
||||
insert into JOUEUR values ('J00002','Bird','Larry','02-Jan-1980','194','SF');
|
||||
insert into JOUEUR values ('J00003','Johnson','Magic','03-Jan-1980','201','PG');
|
||||
insert into JOUEUR values ('J00004','Thomas','Isiah','04-Jan-1980','185','PG');
|
||||
insert into JOUEUR values ('J00005','Oneil','Shaquille','04-Jan-1992','185','C');
|
||||
insert into JOUEUR values ('J00006','Parker','Tony','04-Jan-1996','185','PG');
|
||||
|
||||
|
||||
insert into EQUIPE values ('E00001','Bulls','Chicago','Est','04-Jan-1970');
|
||||
insert into EQUIPE values ('E00002','Lakers','LA','Ouest','06-Jan-1970');
|
||||
insert into EQUIPE values ('E00003','Pistons','Detroit','Est','07-Jan-1970');
|
||||
insert into EQUIPE values ('E00004','Celtics','Boston','Est','09-Jan-1970');
|
||||
insert into EQUIPE values ('E00005','Spurs','San Antonio','Ouest','06-Jan-1971');
|
||||
|
||||
insert into APPARTIENT values ('C00001','J00001','E00001','04-Jan-1980',NULL,10000);
|
||||
insert into APPARTIENT values ('C00002','J00002','E00004','04-Jan-1981',NULL,1000);
|
||||
insert into APPARTIENT values ('C00003','J00003','E00002','04-Jan-1981','04-Jan-2010',3000);
|
||||
insert into APPARTIENT values ('C00004','J00004','E00003','04-Jan-1982',NULL,5000);
|
||||
insert into APPARTIENT values ('C00005','J00005','E00002','04-Jan-1990',NULL,5000);
|
||||
insert into APPARTIENT values ('C00006','J00006','E00005','04-Jan-1990',NULL,5000);
|
||||
|
||||
insert into GAME values ('G00001','04-Jan-2001','E00002','E00001','Londres','Saison',100,101,0);
|
||||
insert into GAME values ('G00002','04-Jan-2001','E00003','E00004','Boston','Saison',102,101,0);
|
||||
insert into GAME values ('G00003','04-May-2001','E00004','E00003','Detroit','Playoff',107,101,0);
|
||||
insert into GAME values ('G00004','04-Apr-2001','E00001','E00002','Miami','Allstar',105,101,0);
|
||||
insert into GAME values ('G00005','04-Apr-2001','E00001','E00003','Miami','Allstar',105,101,0);
|
||||
insert into GAME values ('G00006','04-Apr-2001','E00001','E00004','Miami','Allstar',105,101,0);
|
||||
|
||||
insert into JOUE values ('J00006','G00004',17,18,1,0,1,3,4);
|
||||
insert into JOUE values ('J00005','G00004',17,18,1,0,1,3,4);
|
||||
insert into JOUE values ('J00002','G00004',17,18,1,0,1,3,4);
|
||||
insert into JOUE values ('J00003','G00004',17,18,1,0,1,3,4);
|
||||
insert into JOUE values ('J00001','G00006',17,18,1,0,1,3,4);
|
||||
insert into JOUE values ('J00003','G00006',17,18,1,0,1,3,4);
|
||||
insert into JOUE values ('J00003','G00005',17,18,1,0,1,3,4);
|
||||
insert into JOUE values ('J00004','G00004',17,18,1,0,1,3,4);
|
||||
insert into JOUE values ('J00001','G00003',20,10,4,1,2,2,3);
|
||||
insert into JOUE values ('J00001','G00002',19,11,3,2,2,1,2);
|
||||
insert into JOUE values ('J00001','G00001',18,12,2,3,1,0,1);
|
||||
|
Loading…
Reference in new issue