[英]Can odp.net pass a parameter to a boolean pl/sql parameter?
是否可以正确地将OracleParameter传递给pl / sql存储过程中的布尔参数?
I used the following workaround to bypass this limitation: 我使用以下解决方法绕过此限制:
Here is some sample code: 这是一些示例代码:
using (var connection = new OracleConnection("<connection string>"))
{
var command = new OracleCommand();
command.Connection = connection;
command.CommandText =
"declare v_bool boolean;" +
"begin " +
"v_bool := auth_com.is_valid_username (:username); "+
"if (v_bool = TRUE) then select 1 into :v_result from dual; end if; " +
"if (v_bool = FALSE) then select 0 into :v_result from dual; end if; " +
"end;";
command.Parameters.Add(new OracleParameter { ParameterName = "username", OracleDbType = OracleDbType.NVarchar2, Size=512, Direction = ParameterDirection.Input });
command.Parameters.Add(new OracleParameter { ParameterName = "v_result", OracleDbType = OracleDbType.Decimal, Direction = ParameterDirection.Output });
try
{
connection.Open();
command.ExecuteNonQuery();
}
finally
{
connection.Close();
}
bool success = Convert.ToBoolean(((OracleDecimal)command.Parameters["v_result"].Value).ToInt32());
}
EDIT: 编辑:
Alex Keh from Oracle, october 2013: 来自甲骨文的Alex Keh ,2013年10月:
We're planning on supporting ODP.NET Boolean in the managed provider in the near term, possibly in the middle of next year.
我们计划在短期内(可能在明年年中)在托管提供程序中支持ODP.NET布尔值。
You can not use boolean parameters in SQL. 您不能在SQL中使用布尔参数。 So calling an stored procedure that takes or returns a boolean value won't work in SQL.
因此,调用带有或返回布尔值的存储过程在SQL中是行不通的。 There is no problem using such a procedure from within a pl/sql block.
从pl / sql块中使用这样的过程没有问题。
ADDED from JCallico answer: 从JCallico添加答案:
I used the following workaround to bypass this limitation: 我使用以下解决方法绕过此限制:
Here is some sample code: 这是一些示例代码:
using (var connection = new OracleConnection("<connection string>"))
{
var command = new OracleCommand();
command.Connection = connection;
command.CommandText =
"declare v_bool boolean;" +
"begin " +
"v_bool := auth_com.is_valid_username (:username); "+
"if (v_bool = TRUE) then select 1 into :v_result from dual; end if; " +
"if (v_bool = FALSE) then select 0 into :v_result from dual; end if; " +
"end;";
command.Parameters.Add(new OracleParameter { ParameterName = "username", OracleDbType = OracleDbType.NVarchar2, Size=512, Direction = ParameterDirection.Input });
command.Parameters.Add(new OracleParameter { ParameterName = "v_result", OracleDbType = OracleDbType.Decimal, Direction = ParameterDirection.Output });
try
{
connection.Open();
command.ExecuteNonQuery();
}
finally
{
connection.Close();
}
bool success = Convert.ToBoolean(((OracleDecimal)command.Parameters["v_result"].Value).ToInt32());
}
EDIT: 编辑:
Alex Keh from Oracle, october 2013: 来自甲骨文的Alex Keh ,2013年10月:
We're planning on supporting ODP.NET Boolean in the managed provider in the near term, possibly in the middle of next year.
我们计划在短期内(可能在明年年中)在托管提供程序中支持ODP.NET布尔值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.