Oracle函数的.net类型参数错误

本文关键字:类型参数 错误 net 函数 Oracle | 更新日期: 2023-09-27 18:10:31

这是我的代码(我试图改变名称出于安全原因)

    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["A"].ToString()))
    {
        cmd.Parameters.AddWithValue("A", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("A", int.Parse(ConfigurationManager.AppSettings["A"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["B"].ToString()))
    {
        cmd.Parameters.AddWithValue("B", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("B", ConfigurationManager.AppSettings["B"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["C"].ToString()))
    {
        cmd.Parameters.AddWithValue("C", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("C", ConfigurationManager.AppSettings["C"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["D"]))
    {
        cmd.Parameters.AddWithValue("D", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("D", int.Parse(ConfigurationManager.AppSettings["D"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["E"].ToString()))
    {
        cmd.Parameters.AddWithValue("E", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("E", int.Parse(ConfigurationManager.AppSettings["E"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["F"].ToString()))
    {
        cmd.Parameters.AddWithValue("F", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("F", int.Parse(ConfigurationManager.AppSettings["F"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["G"].ToString()))
    {
        cmd.Parameters.AddWithValue("G", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("G", int.Parse(ConfigurationManager.AppSettings["G"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["H"].ToString()))
    {
        cmd.Parameters.AddWithValue("H", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("H", int.Parse(ConfigurationManager.AppSettings["H"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["I"].ToString()))
    {
        cmd.Parameters.AddWithValue("I", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("I", int.Parse(ConfigurationManager.AppSettings["I"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["J"].ToString()))
    {
        cmd.Parameters.AddWithValue("J", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("J", ConfigurationManager.AppSettings["J"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["K"].ToString()))
    {
        cmd.Parameters.AddWithValue("K", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("K", ConfigurationManager.AppSettings["K"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["L"].ToString()))
    {
        cmd.Parameters.AddWithValue("L", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("L", int.Parse(ConfigurationManager.AppSettings["L"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["M"].ToString()))
    {
        cmd.Parameters.AddWithValue("M", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("M", int.Parse(ConfigurationManager.AppSettings["M"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["N"].ToString()))
    {
        cmd.Parameters.AddWithValue("N", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("N", int.Parse(ConfigurationManager.AppSettings["N"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["O"].ToString()))
    {
        cmd.Parameters.AddWithValue("O", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("O", int.Parse(ConfigurationManager.AppSettings["O"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["P"].ToString()))
    {
        cmd.Parameters.AddWithValue("P", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("P", int.Parse(ConfigurationManager.AppSettings["P"].ToString())).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Q"].ToString()))
    {
        cmd.Parameters.AddWithValue("Q", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("Q", int.Parse(ConfigurationManager.AppSettings["Q"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["R"].ToString()))
    {
        cmd.Parameters.AddWithValue("R", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("R", int.Parse(ConfigurationManager.AppSettings["R"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["S"].ToString()))
    {
        cmd.Parameters.AddWithValue("S", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("S", int.Parse(ConfigurationManager.AppSettings["S"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["T"]))
    {
        cmd.Parameters.AddWithValue("T", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("T", int.Parse(ConfigurationManager.AppSettings["T"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["U"].ToString()))
    {
        cmd.Parameters.AddWithValue("U", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("U", int.Parse(ConfigurationManager.AppSettings["U"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["V"].ToString()))
    {
        cmd.Parameters.AddWithValue("V", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("V", ConfigurationManager.AppSettings["V"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["W"].ToString()))
    {
        cmd.Parameters.AddWithValue("W", DBNull.Value).OracleType = OracleType.Double;
    }
    else
    {
        cmd.Parameters.AddWithValue("W", double.Parse(ConfigurationManager.AppSettings["W"].ToString())).OracleType = OracleType.Double;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["X"].ToString()))
    {
        cmd.Parameters.AddWithValue("X", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("X", ConfigurationManager.AppSettings["X"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Y"].ToString()))
    {
        cmd.Parameters.AddWithValue("Y", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("Y", ConfigurationManager.AppSettings["Y"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Z"].ToString()))
    {
        cmd.Parameters.AddWithValue("Z", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("Z", int.Parse(ConfigurationManager.AppSettings["Z"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["A1"].ToString()))
    {
        cmd.Parameters.AddWithValue("A1", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("A1", ConfigurationManager.AppSettings["A1"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["B1"].ToString()))
    {
        cmd.Parameters.AddWithValue("B1", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("B1", ConfigurationManager.AppSettings["B1"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["C1"].ToString()))
    {
        cmd.Parameters.AddWithValue("C1", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("C1", ConfigurationManager.AppSettings["C1"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["C1"].ToString()))
    {
        cmd.Parameters.AddWithValue("C1", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("C1", ConfigurationManager.AppSettings["C1"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["E1"].ToString()))
    {
        cmd.Parameters.AddWithValue("E1", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("E1", int.Parse(ConfigurationManager.AppSettings["E1"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["F1"].ToString()))
    {
        cmd.Parameters.AddWithValue("F1", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("F1", int.Parse(ConfigurationManager.AppSettings["F1"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["G1"].ToString()))
    {
        cmd.Parameters.AddWithValue("G1", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("G1", ConfigurationManager.AppSettings["G1"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["H1"].ToString()))
    {
        cmd.Parameters.AddWithValue("H1", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("H1", ConfigurationManager.AppSettings["H1"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["I1"].ToString()))
    {
        cmd.Parameters.AddWithValue("I1", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("I1", ConfigurationManager.AppSettings["I1"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["J1"].ToString()))
    {
        cmd.Parameters.AddWithValue("J1", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("J1", ConfigurationManager.AppSettings["J1"].ToString()).OracleType = OracleType.VarChar;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["K1"].ToString()))
    {
        cmd.Parameters.AddWithValue("K1", DBNull.Value).OracleType = OracleType.Number;
    }
    else
    {
        cmd.Parameters.AddWithValue("K1", int.Parse(ConfigurationManager.AppSettings["K1"].ToString())).OracleType = OracleType.Number;
    }
    if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["L1"].ToString()))
    {
        cmd.Parameters.AddWithValue("L1", DBNull.Value).OracleType = OracleType.VarChar;
    }
    else
    {
        cmd.Parameters.AddWithValue("L1", ConfigurationManager.AppSettings["L1"].ToString()).OracleType = OracleType.VarChar;
    }

和这些

  cmd.Parameters.AddWithValue("M1", "24234234234").OracleType = OracleType.VarChar;
                cmd.Parameters.AddWithValue("N1", DateTime.Now.ToString("dd/MMM/yyyy")).OracleType = OracleType.DateTime;//'18/MAY/2015'
                cmd.Parameters.AddWithValue("O1", DateTime.Now.ToString("dd/MMM/yyyy")).OracleType = OracleType.DateTime;

这些参数的实际类型为:

A Numeric(2)
B Varchar(8)
C Varchar(40)
D Numeric(4)
E Numeric(4)
F Numeric(4)
G Numeric(6)
H Numeric(3)
I Numeric(1)
J Varchar(1)
K Varchar(35)
L Numeric(4)
M Numeric(3)
N Numeric(6)
O Numeric(8)
P Numeric(3)
Q Numeric(4)
R Numeric(3)
S Numeric(6)
T Numeric(8)
U Numeric(3)
V Varchar(35)
W Numeric(20,6)
X Varchar(3)
Y Varchar(255)
Z Numeric(1)
A1 Varchar(80)
B1 Varchar(80)
C1 Varchar(5)
D1 Varchar(50)
E1 Numeric(4)
F1 Numeric(4)
G1 Varchar(40)
H1 Varchar(40)
I1 Varchar(40)
J1 Varchar(40)
K1 Numeric(4)
L1 Varchar(1)
M1 Varchar(35)
N1 Datetime
O1 Date

i am getting error:

ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'my function name'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

i打印运行时参数的数量,它是41(正确),所以错误的是这些类型之一。请帮忙,我已经试了两天了,但还没有成功。

Oracle函数的.net类型参数错误

看看你的代码,你错过了一个参数,以及其中一个错误的类型。

"D1"是缺失的部分," p "是不正确的类型(基于你的参数列表),所以它应该从以下更改:

 if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["P"].ToString()))
    {
        cmd.Parameters.AddWithValue("P", DBNull.Value).OracleType = OracleType.VarChar;
    }

:

 if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["P"].ToString()))
    {
        cmd.Parameters.AddWithValue("P", DBNull.Value).OracleType = OracleType.Number;
    }