C# ORA-06550:第 1 行,第 7 列:PLS-00306:参数数量或类型错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11505204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments
提问by Rocco Jr.
I have problem with calling store procedure on Oracle 11g server.
我在 Oracle 11g 服务器上调用存储过程时遇到问题。
stored procedure
存储过程
PROCEDURE get_rit_by_user_id(KDC_KEY IN VARCHAR2,
p_id_utente IN NUMBER,
p_cur_out OUT type_cursor) IS
BEGIN
...
...
...
END
c# code
代码
OracleCommand cmd = new OracleCommand();
cmd.Connection = oracleConnection;
cmd.CommandText = userIdEsercizio + packageName + "GET_RIT_BY_USER_ID";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("KDC_KEY", OracleDbType.Varchar2, kdcKey, ParameterDirection.Input);
cmd.Parameters.Add("P_ID_UTENTE", OracleDbType.Int32, user_id, ParameterDirection.Input);
cmd.Parameters.Add("P_CUR_OUT", OracleDbType.RefCursor, ParameterDirection.Output);
OracleDataReader reader = cmd.ExecuteReader();
cmd.ExecuteReader()throws this exception:
cmd.ExecuteReader()抛出这个异常:
ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'GET_RIT_BY_USER_ID' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
ORA-06550:第 1 行,第 7 列:PLS-00306:调用“GET_RIT_BY_USER_ID”时参数的数量或类型错误 ORA-06550:第 1 行,第 7 列:PL/SQL:语句被忽略
What is wrong with the above code that it gets a wrong number of types of argumentserror?
上面的代码有什么问题,它会wrong number of types of arguments出错?
回答by Marc Gravell
The most common issue with input parameters is null. If kfcKeyor user_idis null(either a null-reference, or a Nullable<T>without a value), then for many providers (and I therefore assume Oracle too) it won't add the parameter. To pass a null, you usually need to pass DBNull.Valueinstead.
输入参数最常见的问题是null. 如果kfcKey或user_id是null(空引用或Nullable<T>没有值的 a),那么对于许多提供者(因此我也假设 Oracle)它不会添加参数。要传递 a null,您通常需要改为传递DBNull.Value。
So: check for nulls.
所以:检查nulls。
cmd.Parameters.Add("KDC_KEY", OracleDbType.Varchar2,
(object)kdcKey ?? DBNull.Value, ParameterDirection.Input);
cmd.Parameters.Add("P_ID_UTENTE", OracleDbType.Int32,
(object)user_id ?? DBNull.Value, ParameterDirection.Input);
回答by D Stanley
Your second parameter is a NUMBER, not an integer. Change the second parameter type to OracleDbType.Decimal
您的第二个参数是 a NUMBER,而不是整数。将第二个参数类型更改为OracleDbType.Decimal
http://docs.oracle.com/cd/B19306_01/win.102/b14307/OracleDbTypeEnumerationType.htm
http://docs.oracle.com/cd/B19306_01/win.102/b14307/OracleDbTypeEnumerationType.htm
Also check the syntax of your Addmethods. It may be better for now to specify the parameter properties more explicitly, even if it makes the code a little more verbose:
还要检查您的Add方法的语法。现在更明确地指定参数属性可能会更好,即使它使代码更冗长:
cmd.Parameters.Add(
new OracleParameter()
{
ParameterName="KDC_KEY",
DbType=OracleDbType.Varchar2,
Value=kdcKey,
Direction=ParameterDirection.Input
}
);
etc.
等等。
Is the proc returning a result set in addition to the cursor? If not use ExecuteNonQueryinstead of Execute
除了游标之外,proc 是否还返回结果集?如果不使用ExecuteNonQuery代替Execute
回答by Manny
Check your parameter spelling, it has to match the Store Procedure variable name, specially, if you have an output variable. I just spent a few hours troubleshooting a similar issue, it turned out I had misspelled my output parameter name.
检查您的参数拼写,它必须与存储过程变量名称匹配,特别是如果您有输出变量。我只花了几个小时来解决类似的问题,结果我拼错了我的输出参数名称。
回答by Christian Shay
You have some kind of user defined type called "type_cursor" but are binding a SYS_REFCURSOR parameter. That is the cause of this error.
您有某种用户定义的类型,称为“type_cursor”,但绑定了 SYS_REFCURSOR 参数。这就是这个错误的原因。
回答by Sarath
I had gone through similar issue and found the root cause silly. If your problem is similar, this may help you.
我经历过类似的问题,发现根本原因很愚蠢。如果您的问题类似,这可能对您有所帮助。
In our case, the exact error message is being returned from a package's procedure call. After 10's of times validating the Java code, its parameters and the back end Package "Body" and its procedure we couldn't figure out any differences.
在我们的例子中,确切的错误消息是从包的过程调用中返回的。经过 10 次验证 Java 代码、其参数和后端包“Body”及其过程后,我们无法找出任何差异。
Then, we noticed that that package has similar procedure with different number of parameters. And the "catch" here is that the package wasn't compiled with the new method that is being called from front end. So, it is going to the old procedure.
然后,我们注意到该包具有类似的过程,但参数数量不同。这里的“捕获”是包不是用从前端调用的新方法编译的。所以,它将进入旧程序。
Please check if this is same with your case.
请检查这是否与您的情况相同。

