Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1463 connectés 

  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  [RESOLU][SQL SERVER] Problème de curseur

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[RESOLU][SQL SERVER] Problème de curseur

n°1366714
CORBASE
Posté le 15-05-2006 à 17:25:06  profilanswer
 

Bonsoir, je sollicite la communauté SQL / SERVER afin de m'aider sur un problème que je ne comprends pas. Cela fait bien 10h que je cherche l'erreur et je ne trouve pas.
J'effectue un curseur qui s'exécute deux fois, et la troisième fois, il ne veut plus ...
 
Voici le code :

Code :
  1. CREATE  PROCEDURE CALCUL_INTEGRALE_VERTICALE
  2.    @jaug_id int
  3. AS
  4. DECLARE @ord MES_COORD,
  5.         @prof MES_COORD,
  6.         @id int,
  7.         @aire_totale float,
  8.         @V_Temp MES_COORD,
  9.         @Prof1 MES_COORD,
  10.         @vitesse float
  11.        
  12. -- // liste de verticales
  13. DECLARE C_verticale CURSOR
  14. FOR
  15.    SELECT DISTINCT mes_abcisse
  16.    FROM MESURE
  17.    WHERE jaug_id = @jaug_id
  18.    ORDER BY mes_abcisse
  19.   -- // RAZ de la table firstintegrale
  20.   DELETE FROM firstintegrale
  21.  
  22.    -- // Premier chargement
  23.    OPEN C_verticale
  24.    FETCH C_verticale INTO @ord
  25.    WHILE @@fetch_Status = 0
  26.       BEGIN
  27.        
  28. SET @aire_totale = 0
  29. -- //création de la liste de chaque point de mesure pour une abcisse
  30. DECLARE C_point CURSOR
  31. FOR
  32.     SELECT mes_id, mes_ordonnee, mes_vitesse
  33.             FROM MESURE
  34.             WHERE jaug_id = @jaug_id
  35.             AND mes_abcisse = @ord
  36.  ORDER BY mes_ordonnee
  37. BEGIN
  38.           -- //premier chargement de points
  39.           OPEN C_point
  40.           FETCH C_point INTO @id, @prof, @vitesse
  41.           SET @V_Temp = @vitesse
  42.           SET @Prof1 = @prof
  43.          
  44.           WHILE @@fetch_Status = 0
  45.             BEGIN
  46.                FETCH C_point INTO @id, @prof, @vitesse
  47.                SET @aire_totale = @aire_totale + (((@prof - @Prof1) * @V_Temp) + (((@prof - @Prof1) * (@vitesse - @V_Temp)) * 0.5)) * 0.01
  48.             
  49.                SET @V_Temp = @vitesse
  50.                SET @Prof1 = @prof       
  51.             END     
  52.            
  53.           -- //ajout de résultat
  54.           INSERT INTO firstintegrale VALUES(@ord, @aire_totale)
  55.          
  56. PRINT 'BOB ' + CONVERT(char, @ord)
  57.           CLOSE C_point
  58.           DEALLOCATE C_point 
  59.          -- // Prochaine abcisse
  60.         FETCH C_verticale INTO @ord
  61.       END
  62.      
  63.     CLOSE C_verticale
  64.     DEALLOCATE C_verticale
  65. END
  66. GO


 
Voici l'erreur (extrait de Analyseur de requete) :

Code :
  1. (2 ligne(s) affectée(s))
  2. (1 ligne(s) affectée(s))
  3. BOB 18                           
  4. (1 ligne(s) affectée(s))
  5. BOB 38                           
  6. Serveur : Msg 16916, Niveau  16, État 1, Procédure CALCUL_INTEGRALE_VERTICALE, Ligne 73
  7. Un curseur nommé 'C_verticale' n'existe pas.
  8. Serveur : Msg 16916, Niveau  16, État 1, Procédure CALCUL_INTEGRALE_VERTICALE, Ligne 76
  9. Un curseur nommé 'C_verticale' n'existe pas.
  10. Serveur : Msg 16916, Niveau  16, État 1, Procédure CALCUL_INTEGRALE_VERTICALE, Ligne 77
  11. Un curseur nommé 'C_verticale' n'existe pas.


 
Le schéma de la table est :

Code :
  1. CREATE TABLE [MESURE] (
  2. [MES_ABCISSE] [MES_COORD] NULL ,
  3. [MES_ORDONNEE] [MES_COORD] NULL ,
  4. [MES_VALEUR] [numeric](18, 0) NULL ,
  5. [MES_TEMP_PRISE] [numeric](18, 0) NULL ,
  6. [MES_FOND] [bit] NULL ,
  7. [MES_ID] [int] IDENTITY (1, 1) NOT NULL ,
  8. [HEL_ID] [char] (7) COLLATE French_CI_AS NOT NULL ,
  9. [JAUG_ID] [int] NOT NULL ,
  10. [MES_VITESSE] [numeric](4, 1) NULL ,
  11. CONSTRAINT [PK_MESURE] PRIMARY KEY  CLUSTERED
  12. (
  13.  [MES_ID]
  14. )  ON [PRIMARY] ,
  15. CONSTRAINT [FK_MESURE_ETRE_PRIS_HELICE] FOREIGN KEY
  16. (
  17.  [HEL_ID]
  18. ) REFERENCES [HELICE] (
  19.  [HEL_ID]
  20. ),
  21. CONSTRAINT [FK_MESURE_JEAUGEAGE] FOREIGN KEY
  22. (
  23.  [JAUG_ID]
  24. ) REFERENCES [JEAUGEAGE] (
  25.  [JAUG_ID]
  26. )
  27. ) ON [PRIMARY]
  28. GO


 
Voici un petit DUMP de la table avec quelques données :
 

Code :
  1. 18,450,,100,,3,"1-15620",1,2.6
  2. 18,300,10,100,,4,"1-15620",1,2.6
  3. 18,150,10,100,,5,"1-15620",1,2.6
  4. 18,60,10,100,,6,"1-15620",1,2.6
  5. 18,10,10,100,,7,"1-15620",1,2.6
  6. 18,0,43,0,,8,"1-15620",1,.0
  7. 38,700,0,0,True,9,"1-15620",1,.0
  8. 38,680,46,100,,10,"1-15620",1,8.2
  9. 38,600,54,100,,11,"1-15620",1,8.4
  10. 38,400,86,100,,12,"1-15620",1,10.4
  11. 38,200,90,100,,13,"1-15620",1,11.1
  12. 38,60,102,100,,14,"1-15620",1,12.0
  13. 38,10,98,100,,15,"1-15620",1,11.4
  14. 38,0,0,0,,16,"1-15620",1,.0
  15. 45,600,10,100,,17,"1-15620",1,2.6
  16. 18,500,10,20,,37,"1-15620",1,2.6
  17. 18,500,10,20,,38,"1-15620",1,2.6
  18. 18,300,10,100,,39,"1-15620",1,2.6
  19. 45,200,10,20,,40,"1-15620",1,2.6
  20. 45,200,10,20,,41,"1-15620",1,2.6
  21. 45,150,10,20,,43,"1-15620",1,2.6
  22. 18,450,20,10,,50,"1-15620",1,5.2
  23. 18,450,,,,51,"1-15620",1,
  24. 18,450,,,,52,"1-15620",1,
  25. 18,450,,,,53,"1-15620",1,
  26. 18,450,,,,54,"1-15620",1,


Message édité par CORBASE le 16-05-2006 à 17:43:21
mood
Publicité
Posté le 15-05-2006 à 17:25:06  profilanswer
 

n°1367978
CORBASE
Posté le 16-05-2006 à 17:42:40  profilanswer
 

Bon, problème résolu :
 

Code :
  1. CREATE    PROCEDURE CALCUL_INTEGRALE_VERTICALE
  2.    @jaug_id int
  3. AS
  4. DECLARE @ord MES_COORD,
  5.         @prof MES_COORD,
  6.         @id int,
  7.         @aire_totale float,
  8.         @V_Temp MES_COORD,
  9.         @Prof1 MES_COORD,
  10.         @vitesse float,
  11. @const_fond int,
  12. @echelle int
  13.        
  14. -- // liste de verticales
  15. DECLARE C_verticale CURSOR
  16. FOR
  17.    SELECT DISTINCT mes_abcisse
  18.    FROM MESURE
  19.    WHERE jaug_id = @jaug_id
  20.    ORDER BY mes_abcisse
  21.   -- // RAZ de la table firstintegrale
  22.   DELETE FROM firstintegrale
  23.  
  24.    -- // Premier chargement
  25.    OPEN C_verticale
  26.    SET @aire_totale = 0
  27.    SET @echelle = (SELECT hauteur_echelle FROM JEAUGEAGE WHERE jaug_id = @jaug_id)
  28.    SET @const_fond = (SELECT jaug_ctefond FROM JEAUGEAGE WHERE jaug_id = @jaug_id)
  29.    FETCH C_verticale INTO @ord
  30.  
  31.    WHILE @@fetch_Status = 0
  32.       BEGIN
  33.        
  34. -- //création de la liste de chaque point de mesure pour une abcisse
  35. DECLARE C_point CURSOR
  36. FOR
  37.     SELECT mes_id, mes_ordonnee, mes_vitesse
  38.             FROM MESURE
  39.             WHERE jaug_id = @jaug_id
  40.             AND mes_abcisse = @ord
  41.  ORDER BY mes_ordonnee
  42. BEGIN
  43.           -- //premier chargement de points
  44.           OPEN C_point
  45.           FETCH C_point INTO @id, @prof, @vitesse
  46.   -- // Calcul du premier tirangle d'aire de la lame
  47.   SET @aire_totale = @aire_totale + ((@vitesse * (@prof - @echelle)) * 0.5)
  48.           SET @V_Temp = @vitesse
  49.           SET @Prof1 = @prof
  50.          
  51.           WHILE @@fetch_Status = 0
  52.             BEGIN
  53.                FETCH C_point INTO @id, @prof, @vitesse
  54.                SET @aire_totale = @aire_totale + (((@prof - @Prof1) * @V_Temp) + (((@prof - @Prof1) * (@vitesse - @V_Temp)) * 0.5)) * 0.01
  55.             
  56.                SET @V_Temp = @vitesse
  57.                SET @Prof1 = @prof       
  58.             END     
  59.           -- // calcul de la fin de l'integrale
  60.   SET @aire_totale = @aire_totale + ((@V_Temp * @const_fond) * 0.5)
  61.           -- //ajout de résultat
  62.           INSERT INTO firstintegrale VALUES(@ord, @aire_totale)
  63.           CLOSE C_point
  64.           DEALLOCATE C_point 
  65.          -- // Prochaine abcisse
  66.         FETCH C_verticale INTO @ord
  67.       END
  68. END
  69.     CLOSE C_verticale
  70.     DEALLOCATE C_verticale
  71. GO


 
C'etait le close et le desallocate qui n'etait pas à la bonne place ...


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  [RESOLU][SQL SERVER] Problème de curseur

 

Sujets relatifs
[Resolu] BATCH - comment executer un programme 32 bit ?php pas interpreté completement par IIS [RESOLU]
svn mirroring : problème de mergebackProblème Macro pour CATIA V5R14
[SQL] Masque "littéral"[Delphi] Application Multi-lingue [résolu]
[résolu]mysql clé étrangère dans une autre base de données[SQL SERVER] Copie de donnees d'une base a une autre
[SAGE] Transformer un bon de commande en bon de livraison en SQL 
Plus de sujets relatifs à : [RESOLU][SQL SERVER] Problème de curseur


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR