PLS-00306:调用的参数的数量或类型错误

时间:2011-11-07 17:24:00

标签: .net oracle odp.net

我正在从.NET应用程序调用Oracle函数,我总是遇到以下异常:   PLS-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;
}

2 个答案:

答案 0 :(得分:3)

像艾伦一样,我不是ODP专家。但是,我知道Oracle将函数的返回值存储为数据字典中的PARAMETER 0。输入参数为12

因此,如果您在之前声明并分配返回值,则可以分配输入参数。

答案 1 :(得分:1)

我不是.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调用中返回返回值。