oracle odp.net 可以将参数传递给布尔 pl/sql 参数吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3099833/
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
Can odp.net pass a parameter to a boolean pl/sql parameter?
提问by haymansfield
Is it possible to correctly pass an OracleParameter to a boolean parameter in a pl/sql stored procedure?
是否可以在 pl/sql 存储过程中将 OracleParameter 正确传递给布尔参数?
采纳答案by Rene
You can not use boolean parameters in SQL. So calling an stored procedure that takes or returns a boolean value won't work in SQL. There is no problem using such a procedure from within a pl/sql block.
您不能在 SQL 中使用布尔参数。所以调用一个接受或返回一个布尔值的存储过程在 SQL 中不起作用。在 pl/sql 块中使用这样的过程没有问题。
ADDED from JCallico answer:
从 JCallico 回答中添加:
I used the following workaround to bypass this limitation:
我使用以下解决方法绕过此限制:
- Wrap the function call using an anonymous block.
- Return an output variable containing 1 or 0.
- Read the output variable and cast it to boolean.
- 使用匿名块包装函数调用。
- 返回一个包含 1 或 0 的输出变量。
- 读取输出变量并将其转换为布尔值。
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 Kehfrom 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 Boolean。
回答by JCallico
I used the following workaround to bypass this limitation:
我使用以下解决方法绕过此限制:
- Wrap the function call using an anonymous block.
- Return an output variable containing 1 or 0.
- Read the output variable and cast it to boolean.
- 使用匿名块包装函数调用。
- 返回一个包含 1 或 0 的输出变量。
- 读取输出变量并将其转换为布尔值。
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 Kehfrom 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 Boolean。