IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PL/SQL Oracle Discussion :

Problème avec ma procédure


Sujet :

PL/SQL Oracle

  1. #1
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2009
    Messages
    68
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Août 2009
    Messages : 68
    Par défaut Problème avec ma procédure
    bonjour, j'ai un souci avec ma procedure(elle est sensée me sortir un truc du genre une facture) qui est la suivante:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    show err;
    		CREATE OR REPLACE PROCEDURE 
    		imprimer_facture(numcom IN  Commandes.num_com%TYPE)
            IS
                 taux            float;
    			 -- Variable pour l'affichage de l''entête de la facture
    			 numeroclient    Clients.num_cli%TYPE;
    			 nomclient       Clients.nom_cli%TYPE;
    			 adresseclient   Clients.adress_cli%TYPE;
    			 telephoneclient Clients.numtel_cli%TYPE;
    			 datecommande    Commandes.date_com%TYPE;
     
    			 -- Variables dans MonCurseur pour l'affichage dans la facture
    			 numeroproduit   Produits.num_pro%TYPE;
    			 libelleproduit  Produits.lib_pro%TYPE;
    			 quantitecommade Ligne_Coms.qte_com%TYPE;
    			 prix_unitaire   Produits.prix_u%TYPE;
    			 prixproduit     Produits.prix_u%TYPE;
    			 MontantTotal    Commandes.mtot_com%TYPE;
     
    			 -- Déclaration du curseur
    			 CURSOR MonCurseur 
    			 IS
    			 SELECT* FROM Commandes,Produits,Clients,Ligne_Coms
    			 WHERE         Commandes.num_com  = numcom
    			 AND           Clients.num_cli    = Commandes.num_com
    			 AND           Ligne_Coms.num_com = Commandes.num_com
    			 AND           Produits.num_pro   = Ligne_Coms.num_pro
    			 ORDER BY      Produits.num_pro asc;--ligne 28
            BEGIN
     
    		    taux:=0.18;
     
    			-- Pour l'affichage de l'entête de la facture
    			SELECT Clients.num_cli,Clients.nom_cli,Clients.adress_cli,Clients.numtel_cli,Commandes.Mtot_Com,Commandes.date_com 
    			INTO   numeroclient,nomclient,adresseclient,telephoneclient,MontantTotal,datecommande
    			FROM   Commandes,Produits,Clients,Ligne_Coms
    			WHERE  Commandes.num_com  = numcom
    			AND    Clients.num_cli    = Commandes.num_com
    			AND    Ligne_Coms.num_com = Commandes.num_com
    			AND    Produits.num_pro   = Ligne_Coms.num_pro;
     
    			 -- Affichage de l'entête de la facture 
    			 DBMS_OUTPUT.PUT_LINE('Client N°    :'||numeroclient);
    			 DBMS_OUTPUT.PUT_LINE('Nom          :'||nomclient);
    			 DBMS_OUTPUT.PUT_LINE('Adresse      :'||adresseclient);
    			 DBMS_OUTPUT.PUT_LINE('Telephone    :'||telephoneclient);
    			 DBMS_OUTPUT.PUT_LINE('______________________________________________________________________________________________________________');
     
    			 -- Affichage du numero et de la date de la commande 
    			 DBMS_OUTPUT.PUT_LINE('Commande N°  :'||numcom);
    			 DBMS_OUTPUT.PUT_LINE('Du           :'||datecommande);
     
    			 -- Affichage des entêtes concernant les différents produits de la facture 
    			 DBMS_OUTPUT.PUT_LINE('Prod N°  |      Libelle      |    QteCom    |   Prix Unitaire   |   Prix Prod   |   TVA   ');
     
    			OPEN   MonCurseur;
               -- FETCH  MonCurseur INTO numeroproduit,libelleproduit,quantitecommade,prix_unitaire;
                --WHILE (MonCurseur%FOUND) 
    			LOOP
    			       FETCH  MonCurseur INTO numeroproduit,libelleproduit,quantitecommade,prix_unitaire;
    			       prixproduit:=quantitecommade*(prix_unitaire + taux); -- Calcul du prix du produit
                       DBMS_OUTPUT.PUT_LINE(numeroproduit||'--'||libelleproduit||'--'||quantitecommade||'--'||prix_unitaire||'--'||prixproduit||'--'||taux);
                END LOOP;
    			CLOSE MonCurseur;
                DBMS_OUTPUT.PUT_LINE('MONTANT TOTAL   :'|| MontantTotal ||'FCFA');             
     
            END ;
    Voici l'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    LINE/COL 	ERROR
    60/11 	PL/SQL: SQL Statement ignored
    60/11 	PLS-00394: nombre de valeurs erroné dans liste INTO d'une instruc tion FETCH
    . Je ne vois pas l'erreur. SOS!!!

  2. #2
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2008
    Messages
    2 954
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2008
    Messages : 2 954
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    CURSOR MonCurseur IS
    SELECT *
    select * ça n'est pas utilisable pour du code en production, il faut selectionner explicitement les 4 colonnes qui t'intéressent.

  3. #3
    Membre Expert Avatar de ojo77
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Décembre 2010
    Messages
    680
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2010
    Messages : 680
    Par défaut
    Personnellement je préfère ce type d'écriture que je trouve plus lisible :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    CREATE OR REPLACE PROCEDURE imprimer_facture(numcom IN  Commandes.num_com%TYPE)
    IS
      taux   float;
      prixproduit float;
     
      numeroclient Clients.num_cli%TYPE;
      nomclient    Clients.nom_cli%TYPE;
      adresseclient   Clients.adress_cli%TYPE;
      telephoneclient Clients.numtel_cli%TYPE;
      datecommande Commandes.date_com%TYPE;
     
      MontantTotal Commandes.mtot_com%TYPE;
     
    BEGIN
     
     taux:=0.18;
     
     -- Pour l'affichage de l'entête de la facture
     SELECT Clients.num_cli,Clients.nom_cli,Clients.adress_cli,Clients.numtel_cli,Commandes.Mtot_Com,Commandes.date_com 
     INTO   numeroclient,nomclient,adresseclient,telephoneclient,MontantTotal,datecommande
     FROM   Commandes,Produits,Clients,Ligne_Coms
     WHERE  Commandes.num_com  = numcom
       AND Clients.num_cli = Commandes.num_com
       AND Ligne_Coms.num_com = Commandes.num_com
       AND Produits.num_pro   = Ligne_Coms.num_pro;
     
      -- Affichage de l'entête de la facture 
      DBMS_OUTPUT.PUT_LINE('Client N° :'||numeroclient);
      DBMS_OUTPUT.PUT_LINE('Nom       :'||nomclient);
      DBMS_OUTPUT.PUT_LINE('Adresse   :'||adresseclient);
      DBMS_OUTPUT.PUT_LINE('Telephone :'||telephoneclient);
      DBMS_OUTPUT.PUT_LINE('______________________________________________________________________________________________________________');
     
      -- Affichage du numero et de la date de la commande 
      DBMS_OUTPUT.PUT_LINE('Commande N°  :'||numcom);
      DBMS_OUTPUT.PUT_LINE('Du     :'||datecommande);
     
      -- Affichage des entêtes concernant les différents produits de la facture 
      DBMS_OUTPUT.PUT_LINE('Prod N°  |   Libelle   | QteCom |   Prix Unitaire   |   Prix Prod   |   TVA   ');
     
     for c in ( SELECT * FROM Commandes,Produits,Clients,Ligne_Coms
                WHERE   Commandes.num_com  = numcom
                  AND     Clients.num_cli = Commandes.num_com
                  AND     Ligne_Coms.num_com = Commandes.num_com
                  AND     Produits.num_pro   = Ligne_Coms.num_pro
                ORDER BY   Produits.num_pro ASC )
     LOOP
         prixproduit:=c.qte_com*(c.prix_u + taux); -- Calcul du prix du produit
         DBMS_OUTPUT.PUT_LINE(c.num_pro||'--'||c.lib_pro||'--'||c.qte_com||'--'||c.prix_u||'--'||prixproduit||'--'||taux);
     END LOOP;
     DBMS_OUTPUT.PUT_LINE('MONTANT TOTAL   :'|| MontantTotal ||'FCFA');    
    END ;
    /
    C'est juste une question de goût j'en conviens ...

  4. #4
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2008
    Messages
    2 954
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2008
    Messages : 2 954
    Par défaut
    Citation Envoyé par ojo77 Voir le message
    C'est juste une question de goût j'en conviens ...
    +1
    Un for loop est quand même beaucoup plus simple à écrire/lire qu'un open loop fetch exit close...
    Je pense qu'il n'y a pas photo !

Discussions similaires

  1. Problème avec une procédure
    Par Thomad dans le forum SQL
    Réponses: 9
    Dernier message: 24/09/2007, 15h07
  2. Petit problème avec une procédure stockée
    Par Poulain dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 18/05/2007, 18h58
  3. [VB.NET 2.0] - Problème avec une procédure stockée
    Par Khrysby dans le forum Accès aux données
    Réponses: 1
    Dernier message: 14/05/2007, 15h25
  4. problème avec une procédure recursive
    Par vbcasimir dans le forum SQL
    Réponses: 1
    Dernier message: 10/06/2005, 16h38
  5. Problème avec une procédure stockée
    Par in dans le forum Langage SQL
    Réponses: 4
    Dernier message: 27/05/2003, 15h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo