问题
I'm invoking an Oracle function from a .NET application and I always get following exception: PLS-00306: wrong number or types of arguments in call to 'TF_GETNODES'
Here is the definition of the Oracle function:
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;
And here is my .NET code:
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;
}
回答1:
Like Allan I'm not an ODP expert. However, I do know that Oracle stores the return value of a function as PARAMETER 0
in the Data Dictionary. The input parameters are 1
, 2
, etc.
So, if you declare and assign the return value before you assign the input parameters it might work.
回答2:
I'm not an expert on the .NET side of things, but it looks to me like you're setting up your UDT as a parameter, rather than as a return value. Try dropping your function and replacing it with the following procedure:
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;
/
If that works, you can either leave it as-is, or investigate how to get the return value back in the .NET call.
来源:https://stackoverflow.com/questions/8040115/pls-00306-wrong-number-or-types-of-arguments-in-call-to