问题描述
我在将布尔参数传递给Oracle中的过程时遇到问题.我收到错误
I have problem to pass boolean parameter to my procedure in Oracle. I get error
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'LOG_ENTRY'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored"
Oracle中的过程
Procedure in Oracle:
log_entry(p_rqserial in integer,
p_orig in varchar,
p_type in char,
p_objname in varchar,
p_info in varchar,
p_text in varchar, p_with_commit boolean)
这是我的代码:
cmd = new Oracle.DataAccess.Client.OracleCommand("Vbank_pkg.vb_log_entry", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("p_rqserial", OracleDbType.Int32).Value = Log_Serial;
cmd.Parameters.Add("p_orig", OracleDbType.Varchar2).Value = "\'" + p_orig + "\'";
cmd.Parameters.Add("p_type", OracleDbType.Char).Value = "\'" + p_type + "\'";
cmd.Parameters.Add("p_objname", OracleDbType.Varchar2).Value = "\'" + p_objname + "\'";
cmd.Parameters.Add("p_info", OracleDbType.Varchar2).Value = "\'" + p_info + "\'";
cmd.Parameters.Add("p_text", OracleDbType.Varchar2).Value = "\'" + p_text + "\'";
cmd.Parameters.Add("p_with_commit", OracleDbType.Char).Value =true;
cmd.ExecuteNonQuery();//Here error
有人知道该怎么做吗?因为我找不到任何解决方案,所以很多人说不可能将bool参数从C#传递到Oracle,但是我不敢相信没有办法.
Do any know how to do this? Because I can't find any solution and many people says it's inpossible to pass bool parameter from C# to Oracle but I can't believe there is no way.
推荐答案
尝试将OracleCommand
的BindByName
属性用作true
,以强制数据提供者按名称而不是仅针对索引绑定这些参数.您不需要将'
作为参数传递.它是在ado.net
中带有参数的引线.
Try using BindByName
property of OracleCommand
as true
to force the data provider bind these parameters by name and not just for the index. You do not need to pass the '
as parameters. It is lead with parameters in the ado.net
.
ODP.NET不支持布尔数据类型.只需将1
或0
用作char
值即可将其保留.
ODP.NET does not support Boolean data type. Just use 1
or 0
as a char
value to persist it.
对于样品:
cmd = new Oracle.DataAccess.Client.OracleCommand("Vbank_pkg.vb_log_entry", con);
cmd.BindByName = true;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("p_rqserial", OracleDbType.Int32).Value = Log_Serial;
cmd.Parameters.Add("p_orig", OracleDbType.Varchar2).Value = p_orig;
cmd.Parameters.Add("p_type", OracleDbType.Char).Value = p_type;
cmd.Parameters.Add("p_objname", OracleDbType.Varchar2).Value = p_objname;
cmd.Parameters.Add("p_info", OracleDbType.Varchar2).Value = p_info;
cmd.Parameters.Add("p_text", OracleDbType.Varchar2).Value = p_text;
cmd.Parameters.Add("p_with_commit", OracleDbType.Char).Value = "1";
cmd.ExecuteNonQuery();
这篇关于如何将布尔参数传递给Oracle过程C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!