Bonjour j'ai une procédure stockée qui me sort en paramètre de sortie un tableau d'enregistrement.

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
 
TYPE T_REC_TEST IS RECORD (
   libelleCTC VARCHAR2(20),
   resteCoupure VARCHAR2(20),
   stock VARCHAR2(20),
   traficTrie VARCHAR2(20),
   tauxReste VARCHAR2(20));
-- Table de records --
TYPE TAB_T_REC_TEST IS TABLE OF T_REC_TEST INDEX BY BINARY_INTEGER ;
 
 
 
 
PROCEDURE P_TB_TEST2(PDI_JOURNEE_POSTALE IN DATE, PTO_TEST OUT TAB_T_REC_TEST)
IS
    -- curseur
	v_cur Pkg_Tableaux_Bord_Reste.r_cursor;
 
	-- variables
	fileHandler UTL_FILE.FILE_TYPE;
	resteCoupure INTEGER;
	stock INTEGER;
	traficTrie INTEGER;
	codeCTC CHAR(6);
	libelleCTC VARCHAR2(20);
	idCTC INTEGER;
 
	--PTO_ECO_DEP TAB_T_REC_ECO_DEP;
 
	indice INTEGER;
 
BEGIN
 
	-- Ouverture du fichier de log
	fileHandler := UTL_FILE.FOPEN('TRC_DIR', 'ECO_DEPART.LOG', 'w');
	indice := 1;
 
    -- recupération de la liste des établissements
	P_GET_ETAB_STOCK_RESTE (v_cur,PDI_JOURNEE_POSTALE);
 
 
 
    LOOP
      FETCH v_cur INTO codeCTC , libelleCTC, idCTC;
   	  		EXIT WHEN v_cur%NOTFOUND;
 
 
		PTO_TEST(indice).libelleCTC := libelleCTC;
 
		P_GET_RESTE_BY_ETAB (idCTC, -- id du ctc
		                     '2', -- code catégorie "Ecopli"
							 1, -- code niveau_tri "Départ"
							 PDI_JOURNEE_POSTALE,
							 resteCoupure);
 
		P_GET_STOCK_MACROPT_BY_ETAB (idCTC, -- id du ctc
		                             '2', -- code catégorie "Ecopli"
							 		 1, -- code niveau_tri "Départ"
							 		 PDI_JOURNEE_POSTALE,
							 		 stock);
 
		P_GET_TRAFIC_TRIE_CAT_BY_ETAB (idCTC, -- id du ctc
		                               '2', -- code catégorie "Ecopli"
							 	   	   1, -- code niveau_tri "Départ"
							 	   	   PDI_JOURNEE_POSTALE,
							 	  	   traficTrie);
 
		PTO_TEST(indice).resteCoupure := '' || resteCoupure;
		PTO_TEST(indice).stock := '' || stock;
		PTO_TEST(indice).traficTrie := '' ||  traficTrie;
 
		IF (traficTrie IS NOT NULL AND traficTrie != 0) THEN
		   PTO_TEST(indice).tauxReste := '' ||  (stock /traficTrie);
		ELSE
			PTO_TEST(indice).tauxReste := '0';
		END IF;
 
		indice := indice + 1;
	END LOOP;
	CLOSE v_cur;
 
	FOR i IN 1..PTO_TEST.COUNT LOOP
		UTL_FILE.PUT_LINE(fileHandler, ' **** code : ' || PTO_TEST(i).libelleCTC);
		UTL_FILE.PUT_LINE(fileHandler, ' **** reste : ' || PTO_TEST(i).resteCoupure);
		UTL_FILE.PUT_LINE(fileHandler, ' **** stock : ' || PTO_TEST(i).stock);
		UTL_FILE.PUT_LINE(fileHandler, ' **** trie : ' || PTO_TEST(i).traficTrie);
		UTL_FILE.PUT_LINE(fileHandler, ' **** taux Reste : ' || PTO_TEST(i).tauxReste);
    END LOOP;
 
	-- Fermeture du fichier de log
	UTL_FILE.FCLOSE(fileHandler);
 
 
	EXCEPTION
	WHEN utl_file.invalid_path THEN
		 RAISE_APPLICATION_ERROR(-20000, 'Erreur: répertoire / nom de fichier invalide');
	WHEN OTHERS THEN
		 RAISE;
 
END P_TB_TEST2;

Je cherche à faire appel de cette procédure stockée à partir de mon code C#

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
 
		public void test2() 
		{
 
			OracleConnection myConnection = new OracleConnection();
			try 
			{
				string strConn = "user id=HGADEV_AA5;data source=BOUCLAGE_V3;password=HGADEV_AA5";
				myConnection.ConnectionString = strConn;
				myConnection.Open();
 
 
				OracleCommand cmd = new OracleCommand( "PKG_TABLEAUX_BORD_RESTE.P_TB_TEST2", myConnection);
				cmd.CommandType=CommandType.StoredProcedure;
 
				OracleParameter Param1 = new OracleParameter();
				Param1.OracleDbType = OracleDbType.Date;
				Param1.Direction = ParameterDirection.Input;
				Param1.Value= "15/11/2005";
 
 
 
				OracleParameter Param2 = new OracleParameter();
				Param2.OracleDbType = OracleDbType.Varchar2;
				Param2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
				Param2.Direction = ParameterDirection.Output;
 
				Param2.Value = null;
 
 
				int max = 3;
 
 
				int maxVarChar = 20;
				int [] tbOracle = new int[max];
				for (int i=0; i<tbOracle.Length; i++) 
				{
					tbOracle[i]=maxVarChar;
				}
				Param2.ArrayBindSize = tbOracle;
 
 
				cmd.Parameters.Add(Param1);
				cmd.Parameters.Add(Param2);
 
 
				cmd.ExecuteNonQuery();
				System.Console.WriteLine(cmd.Parameters[1].Value);
			} 
			catch (Exception ex)
			{
				string err = ex.StackTrace;
			} 
			finally 
			{
				myConnection.Close();
			}
		}

Mais ca ne fonctionne pas très bien car en fait je ne peux pas définir à l'avance le nombre d'éléments de mon tableau d'enregistrement et du coup je ne peux pas renseigner le Param2.ArrayBindSize...

Est ce que certaines personnes ont déjà réliser ce genre d'appel.