我从。net应用程序调用Oracle函数,我总是得到以下异常:pl -00306:调用'TF_GETNODES'时参数数量或类型错误
下面是Oracle函数的定义:FUNCTION "IMPACTNET"."TF_GETNODES"
(
DIMENSIONKEY IN NVARCHAR2,
PARENTNODE IN NVARCHAR2,
PARASTRING IN NVARCHAR2
) RETURN IMPACTNET.TREE_NODE_TABLE IS
treeNodes IMPACTNET.TREE_NODE_TABLE;
BEGIN
treeNodes:=IMPACTNET.TREE_NODE_TABLE();
for i in 1..2
loop
treeNodes.extend;
treeNodes(i) := IMPACTNET.TREE_NODE(DIMENSIONKEY || i, PARENTNODE || i, 0, 0, PARASTRING || i, 0);
end loop;
RETURN treeNodes;
END;
下面是我的。net代码:
var treeNodes = new TreeNodesTable();
using (var connection = CreateConnection())
using (var command = new OracleCommand { Connection = connection, CommandType = CommandType.StoredProcedure, CommandText = "IMPACTNET.TF_GETNODES" })
{
command.Parameters.Add("DIMENSIONKEY", OracleDbType.NVarchar2, ParameterDirection.Input).Value = "dimension key";
command.Parameters.Add("PARENTNODE", OracleDbType.NVarchar2, ParameterDirection.Input).Value = "parent node";
command.Parameters.Add("PARASTRING", OracleDbType.NVarchar2, ParameterDirection.Input).Value = "para string";
var p1 = new OracleParameter
{
ParameterName = "treeNodes",
OracleDbType = OracleDbType.Object,
UdtTypeName = "IMPACTNET.TREE_NODE_TABLE",
Direction = ParameterDirection.ReturnValue,
Value = treeNodes
};
command.Parameters.Add(p1);
connection.Open();
command.ExecuteNonQuery();
treeNodes = (TreeNodesTable)p1.Value;
}
和Allan一样,我不是ODP专家。然而,我知道Oracle将函数的返回值存储为PARAMETER 0
在数据字典中。输入参数为1
、2
等
所以,如果你在输入参数之前声明并赋值返回值,它可能会起作用
我不是。net方面的专家,但在我看来,您将UDT设置为参数,而不是返回值。尝试删除您的函数并用以下过程替换它:
PROCEDURE "IMPACTNET"."TF_GETNODES"
(
DIMENSIONKEY IN NVARCHAR2,
PARENTNODE IN NVARCHAR2,
PARASTRING IN NVARCHAR2,
treeNodes OUT IMPACTNET.TREE_NODE_TABLE
) IS
BEGIN
treeNodes:=IMPACTNET.TREE_NODE_TABLE();
for i in 1..2 loop
treeNodes.extend;
treeNodes(i) := IMPACTNET.TREE_NODE(DIMENSIONKEY || i,
PARENTNODE || i,
0,
0,
PARASTRING || i,
0);
end loop;
END;
/
如果可以,您可以保持原样,或者研究如何在. net调用中获得返回值。