简体   繁体   English

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

[英]PLS-00306: wrong number or types of arguments when calling oracle function

I have a simple oracle function as below 我有一个简单的oracle函数如下

create or replace function get_area(
mem_id IN VARCHAR2,
P_date    DATE DEFAULT SYSDATE)
RETURN NUMBER
IS
  v_area_id NUMBER;
BEGIN
v_area_id := 0;
RETURN v_area_id ;
end;

(its a testing function so just assigning 0 and returning back the variable) (它具有测试功能,因此只需分配0并返回变量即可)

We are calling the same in C# as below 我们在C#中的调用如下

            ora_con.Open();
            OracleCommand cmd = ora_con.CreateCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = ora_con;

            cmd.CommandText = "schema.get_area";

            OracleParameter mem_id = new OracleParameter();
            mem_id.OracleDbType = OracleDbType.Varchar2;
            mem_id.Direction = ParameterDirection.Input;
            mem_id.Value = m_id1;

            OracleParameter P_date = new OracleParameter();
            P_date.OracleDbType = OracleDbType.Date;
            P_date.Direction = ParameterDirection.Input;
            P_date.Value = DateTime.Now;

            OracleParameter v_area_id = new OracleParameter();
            v_area_id.OracleDbType = OracleDbType.Int64;
            v_area_id.Direction = ParameterDirection.ReturnValue;
            v_area_id.Size = 1000;

            cmd.Parameters.Add(mem_id);
            cmd.Parameters.Add(P_date);
            cmd.Parameters.Add(v_area_id);

            cmd.ExecuteNonQuery();
            area_id = Convert.ToInt64(cmd.Parameters["v_area_id"].Value);

while executing the same getting the below error 执行相同的同时出现以下错误

ORA-06550: line 1, column 15: PLS-00306: wrong number or types of arguments in call to 'GET_AREA' ORA-06550: line 1, column 7: PL/SQL: Statement ignored ORA-06550:第1行,第15列:PLS-00306:调用“ GET_AREA”时参数的数量或类型错误ORA-06550:第1行,第7列:PL / SQL:语句被忽略

From the docs 来自文档

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/odpnt/featOraCommand.html#GUID-4D32E59C-1BC0-4567-994E-B0EF3D61D3C4 https://docs.oracle.com/zh_CN/database/oracle/oracle-database/12.2/odpnt/featOraCommand.html#GUID-4D32E59C-1BC0-4567-994E-B0EF3D61D3C4

When binding by position (default) to a function, ODP.NET expects the return value to be bound first, before any other parameters. 当按位置(默认)绑定到函数时,ODP.NET期望返回值首先绑定,然后再绑定其他任何参数。

so move your return value parameter to be the first one in your list. 因此,将您的返回值参数移到列表中的第一个。

As I read in this similar issue , probably you're declaring parameters in wrong order since Oracle stores return value as index 0 inside parameter list and input parameters followed suit. 正如我在这个类似的问题中所读到的那样,可能是由于错误的顺序声明了参数,因为Oracle将返回值存储为参数列表内的索引0,而输入参数也随之而来。

Try to adjust parameter order so that the return value assigned first, since mem_id has type of VARCHAR2 and incompatible with NUMBER type: 尝试调整参数顺序,以便首先分配返回值,因为mem_id类型为VARCHAR2并且与NUMBER类型不兼容:

cmd.Parameters.Add(v_area_id); // this should be added first
cmd.Parameters.Add(mem_id);
cmd.Parameters.Add(P_date);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决此问题“ PLS-00306:呼叫中参数的数量或类型错误……” - How to resolve this “PLS-00306: wrong number or types of arguments in call…” PLS-00306:C#中的参数数目或类型错误 - PLS-00306: wrong number or types of arguments error in C# 使用PLS-00306调用带有Char Out参数错误的Oracle存储过程:调用中的参数数目或类型错误 - Call Oracle Stored Procedure with Char Out Parameter errors with PLS-00306: wrong number or types of arguments in call 运行不带参数的过程时出错:PLS-00306:调用中参数的数目或类型错误 - Error while running procedure without parameter: PLS-00306: wrong number or types of arguments in call ORA-06550:第1行第7列:PLS-00306:参数的数量或类型错误 - ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments ORA-06550:第 1 行,第 7 列:PLS-00306:调用“INSERTBILL”时 arguments 的编号或类型错误 - ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'INSERTBILL' 从 C# 代码隐藏调用存储过程时出错:“PLS-00306:调用中的参数数量或类型错误” - Error in call from C# code-behind to a stored procedure: “PLS-00306: wrong number or types of arguments in call to” .NET的Oracle sp调用错误(PLS-00306) - Oracle sp call error with .NET (PLS-00306) 从C#调用包函数:PLS-00306 - Call a package function from C#: PLS-00306 nPLS-00306:调用中参数的数量或类型错误 - nPLS-00306: wrong number or types of arguments in call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM