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

  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  [PL/SQL] Collection

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[PL/SQL] Collection

n°1251605
lapartdomb​re
Posté le 23-11-2005 à 16:05:35  profilanswer
 

Bonjour,
 
je cherche à faire une procédure PL/SQL qui me renvoit une collection pour afficher ensuite cette collection dans une page aspx.
 
Il s'agirait d'une collection contenant 5 champs que j'alimenterai via des requetes. En fait une requete pour le premier champ et en fonction  de la valeur de retour de ce champ, je dois faire des requetes différentes pour alimenter les autres champs.
 
Comment faire cette collection???

mood
Publicité
Posté le 23-11-2005 à 16:05:35  profilanswer
 

n°1252084
lapartdomb​re
Posté le 24-11-2005 à 10:46:04  profilanswer
 

Est ce que cela semble cohérent
 

Code :
  1. CREATE OR REPLACE PACKAGE PKG_TB IS
  2. -- Record --
  3. TYPE T_REC_ECO IS RECORD (
  4. libelleCTC Varchar2(20),
  5. resteCoupure INTEGER,
  6. stock INTEGER,
  7. traficTrie INTEGER,
  8. tauxReste number);
  9. -- Table de records --
  10. TYPE TAB_T_REC_ECO IS TABLE OF T_REC_ECO index by binary_integer ;
  11. PROCEDURE GetResteCoupureStock  (  PCI_CODE_CATEGORIE  IN CHAR,
  12.                                    PNI_CODE_NIVEAU_TRI  IN NUMBER,
  13.           PTO_RES OUT TAB_T_REC_ECO);
  14. END PKG_TB;
  15. /
  16. CREATE OR REPLACE PACKAGE BODY PKG_TB AS
  17. PROCEDURE GetResteCoupureStock  (  PCI_CODE_CATEGORIE  IN CHAR,
  18.                                    PNI_CODE_NIVEAU_TRI IN NUMBER,
  19.           PTO_RES OUT TAB_T_REC_ECO) IS
  20. codeCTC INTEGER;
  21. resteCoupure INTEGER;
  22. stock INTEGER;
  23. traficTrie INTEGER;
  24. fileHandler UTL_FILE.FILE_TYPE;
  25. indice INTEGER;
  26. codeZT INTEGER;
  27. traficTraite INTEGER;
  28. traficDefinitif INTEGER;
  29. -- Record --
  30. TYPE T_REC_ECO IS RECORD (
  31. libelleCTC Varchar2(20),
  32. resteCoupure INTEGER,
  33. stock INTEGER,
  34. traficTrie INTEGER,
  35. tauxReste number);
  36. -- Table de records --
  37. TYPE TAB_T_REC_ECO IS TABLE OF T_REC_ECO index by binary_integer ;
  38. t_rec TAB_T_REC_ECO ; -- variable tableau d'enregistrements
  39. BEGIN
  40.     -- Ouverture du fichier de log
  41.    fileHandler := UTL_FILE.FOPEN('TRC_DIR', 'eco_depart.log', 'w');
  42.    stock := 0 ;
  43.    resteCoupure := 0 ;
  44.    traficTrie := 0;
  45.    indice := 1;
  46.    FOR r IN (
  47.         -- recuperation de la liste des etablissement
  48.         select distinct(ctc.code_ctc ),
  49.                ctc.libelle_ctc,
  50.                ctc.id_ctc
  51.         from ctc, stock_etablissement se, stock_macro_pt smp
  52.         where ctc.id_ctc = se.id_ctc
  53.           and (smp.stock != 0 or smp.reste_en_coupure != 0)
  54.           and smp.id_stock_etablissemen = se.id_stock_etablissemen
  55.           and se.journee_postale = '15/11/2005'
  56.           and ctc.date_suppression is null
  57.           and se.date_suppression is null
  58.    )
  59.    LOOP
  60.     UTL_FILE.PUT_LINE(fileHandler, 'code : ' || r.libelle_ctc);
  61.     t_rec(indice).libelleCTC := r.libelle_ctc;
  62.     for s in (
  63.         select smp.reste_en_coupure,
  64.                smp.stock,
  65.                mp.id_macro_pt,
  66.                zt.code_zt
  67.         from ctc, stock_etablissement se, stock_macro_pt smp, macro_pt mp, categorie cat, niveau_tri nt, zt
  68.         where ctc.id_ctc = se.id_ctc
  69.           and (smp.stock != 0 or smp.reste_en_coupure != 0)
  70.           and smp.id_stock_etablissemen = se.id_stock_etablissemen
  71.           and se.journee_postale = '15/11/2005'
  72.           and mp.id_macro_pt = smp.id_macro_pt
  73.           and mp.id_categorie = cat.id_categorie
  74.           and mp.id_niveau_tri = nt.id_niveau_tri
  75.           and cat.code_categorie = PCI_CODE_CATEGORIE
  76.           and nt.code_nt = PNI_CODE_NIVEAU_TRI
  77.           and ctc.date_suppression is null
  78.           and se.date_suppression is null
  79.           and mp.date_suppression is null
  80.           and cat.date_suppression is null
  81.           and nt.date_suppression is null
  82.           and ctc.id_ctc = r.id_ctc
  83.           and zt.id_zt = mp.id_zt
  84.     )
  85.     LOOP
  86.         resteCoupure := resteCoupure + s.reste_en_coupure;
  87.         stock := stock + s.stock;
  88.          UTL_FILE.PUT_LINE(fileHandler, 'macrpt : ' || s.id_macro_pt);
  89.          UTL_FILE.PUT_LINE(fileHandler, 'code zt : ' || s.code_zt);
  90.     -- recuperation trafic trié
  91.     if (s.code_zt = '2') then
  92.       select sum(t.trafic_traite) into traficTraite
  93.       from  macro_pt mp, categorie cat, niveau_tri nt, chaine ch, trafic t, zt
  94.       where cat.date_suppression is null
  95.         and nt.date_suppression is null
  96.         and zt.date_suppression is null
  97.         and t.date_suppression is null
  98.         and mp.id_macro_pt = s.id_macro_pt
  99.         and mp.id_categorie = cat.id_categorie
  100.         and mp.id_niveau_tri = nt.id_niveau_tri
  101.         and cat.code_categorie = PCI_CODE_CATEGORIE
  102.         and nt.code_nt = PNI_CODE_NIVEAU_TRI
  103.         and ch.id_macro_pt = s.id_macro_pt
  104.         and t.id_chaine = ch.id_chaine
  105.         and t.journee_postale = '15/11/2005'
  106.         and zt.id_zt = mp.id_zt
  107.         and zt.code_zt = 2;
  108.       if traficTraite > 0 then
  109.          traficTrie := traficTrie + traficTraite;
  110.       end if;
  111.        UTL_FILE.PUT_LINE(fileHandler, 'traficTraite : ' || traficTraite);
  112.     end if;
  113.     if   (s.code_zt = 1)  then
  114.       select sum(trafic_definitif) into traficDefinitif
  115.       from ctc, stock_etablissement se, stock_macro_pt smp, macro_pt mp, categorie cat, niveau_tri nt, chaine ch, trafic t, zt
  116.       where cat.date_suppression is null
  117.         and nt.date_suppression is null
  118.         and zt.date_suppression is null
  119.         and t.date_suppression is null
  120.         and mp.id_macro_pt = s.id_macro_pt
  121.         and mp.id_categorie = cat.id_categorie
  122.         and mp.id_niveau_tri = nt.id_niveau_tri
  123.         and cat.code_categorie = PCI_CODE_CATEGORIE
  124.         and nt.code_nt = PNI_CODE_NIVEAU_TRI
  125.         and ch.id_macro_pt = s.id_macro_pt
  126.         and t.id_chaine = ch.id_chaine
  127.         and t.journee_postale = '15/11/2005'
  128.         and zt.id_zt = mp.id_zt
  129.         and zt.code_zt = 1;
  130.       UTL_FILE.PUT_LINE(fileHandler, 'traficDefinitif : ' || traficDefinitif);
  131.       if traficDefinitif > 0 then
  132.          traficTrie := traficTrie + traficDefinitif;
  133.       end if;
  134.      end if;
  135.     END LOOP;
  136.     t_rec(indice).resteCoupure := resteCoupure;
  137.     t_rec(indice).stock := stock;
  138.     t_rec(indice).traficTrie := traficTrie;
  139.     if traficTrie != 0 then
  140.        t_rec(indice).tauxReste := stock / traficTrie;
  141.     end if;
  142.      UTL_FILE.PUT_LINE(fileHandler, 'reste : ' || resteCoupure);
  143.      UTL_FILE.PUT_LINE(fileHandler, 'stock : ' || stock);
  144.     UTL_FILE.PUT_LINE(fileHandler, 'traficTrie : ' || traficTrie);
  145.     UTL_FILE.PUT_LINE(fileHandler, 'tauxReste : ' || t_rec(indice).tauxReste);
  146.     indice := indice + 1;
  147.    END LOOP;
  148.   -- PTO_RES :=t_rec;
  149.    -- Fermeture du fichier de log
  150.    UTL_FILE.FCLOSE(fileHandler);
  151. EXCEPTION
  152.    WHEN utl_file.invalid_path THEN
  153.      RAISE_APPLICATION_ERROR(-20000, 'Erreur: répertoire / nom de fichier invalide');
  154.    WHEN OTHERS THEN
  155.       RAISE;
  156. END GetResteCoupureStock;
  157. END PKG_TB;
  158. /



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

  [PL/SQL] Collection

 

Sujets relatifs
[SQL] Questions basiques sur SQL[SQL Server/ADO/ASP] ADO et procédures stockées distribuées
[SQL] aide pour une requete contenant MIN,MAX et COUNT[PL/SQL] traitement de date
SQL en local chez soi?[SQL] Nombre de champs, optimisation
Site web perso et modification de freeware : SQL ok ? (PHP+SQL)[SQL] Disctinct sur plusieurs champs
création de base SQL Serveur en visual basic.net[Oracle/SQL] recuperer l'heure GMT
Plus de sujets relatifs à : [PL/SQL] Collection


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