C#調(diào)用oracle中帶數(shù)組的存儲(chǔ)過(guò)程
--存儲(chǔ)過(guò)程
CREATE OR REPLACE PACKAGE pg_test IS
TYPE idArrayPg is table of integer index by BINARY_INTEGER;
PROCEDURE p_test(ids IN idArrayPg
);
END pg_test;
CREATE OR REPLACE PACKAGE BODY pg_test IS
PROCEDURE p_test(ids IN idArrayPg
) AS
l_index number;
BEGIN
l_index:= ids.first;--使用first方法
loop
dbms_output.put_line(l_index ||':'|| ids(l_index));
exit when l_index = ids.LAST;
l_index :=ids.next(l_index);
end loop;
END p_test;
END pg_test;
--pl/sql測(cè)試程序
declare
ig_test.idarrads pypg;
begin
ids(1) := 1;
ids(2) := 2;
ids(3) := 3;
pg_test.p_test(ids => ids);
end;
//C#中調(diào)用
cmd = new OracleCommand("pg_test.p_test", con);
cmd.CommandType = CommandType.StoredProcedure;OracleParameter param1 = cmd.Parameters.Add("param1", OracleDbType.Int32);
param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
param1.Direction = ParameterDirection.Input;pg_test.p_test", con);
cmd.CommandType = CommandType.StoredProcedure;OracleParameter param1 = cmd.Parameters.Add("param1", OracleDbType.Int32);
param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
param1.Direction = ParameterDirection.Input;
<strong>param1.Value = new Int[3]{1,2,3};</strong>
param1.Size = 3;cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
<strong>上述代碼經(jīng)測(cè)試,運(yùn)行正確.</strong>
<strong>注:</strong>
<strong>在項(xiàng)目開(kāi)發(fā)過(guò)程中,曾試圖將數(shù)組定義為:</strong>
TYPE idArrayPg is table of integer;
在C#中調(diào)用存在問(wèn)題,但在JAVA中調(diào)用正常.至于如何在C#中調(diào)用定義的數(shù)組不帶index by BINARY_INTEGER,目前還未找到解決方案.
想了解更多?現(xiàn)在就開(kāi)始免費(fèi)體驗(yàn)