简体   繁体   English

odp.net可以将参数传递给布尔值pl / sql参数吗?

[英]Can odp.net pass a parameter to a boolean pl/sql parameter?

是否可以正确地将OracleParameter传递给pl / sql存储过程中的布尔参数?

I used the following workaround to bypass this limitation: 我使用以下解决方法绕过此限制:

  1. Wrap the function call using an anonymous block. 使用匿名块包装函数调用。
  2. Return an output variable containing 1 or 0. 返回包含1或0的输出变量。
  3. Read the output variable and cast it to boolean. 读取输出变量并将其转换为布尔值。

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: 我使用以下解决方法绕过此限制:

  1. Wrap the function call using an anonymous block. 使用匿名块包装函数调用。
  2. Return an output variable containing 1 or 0. 返回包含1或0的输出变量。
  3. Read the output variable and cast it to boolean. 读取输出变量并将其转换为布尔值。

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.

相关问题 如何解析作为odp.net参数值传递的日期? - How to parse the date passed as a odp.net parameter value? 托管的ODP.Net-SELECT中的参数导致产生ReadOnly列 - Managed ODP.Net - Parameter in SELECT resulting in ReadOnly columns ODP.NET:参数类型在相同的CommandText上“缓存” - ODP.NET : Parameter Types “cached” on identical CommandText 如何使用ODP.NET检查ReturnValue参数是否为null? - How to check ReturnValue parameter for null using ODP.NET? odp.net使用用户定义参数的输出参数运行oracle存储过程 - odp.net run oracle stored procedure with output parameter of user defined parameter 为什么这个PL / SQL查询不能使用ODP.NET执行 - Why this PL/SQL query doesn't execute using ODP.NET 使用odp.net和pl / sql存储过程从oracle表检索数据的最佳方法是什么? - What is the best way to retrieve data from an oracle table using odp.net and pl/sql stored procedures? 企业库ODP.NET调用返回ORA-06502:PL / SQL:数字或值错误 - Enterprise Library ODP.NET call returns ORA-06502: PL/SQL: numeric or value error ODP.Net new OracleConnection "Value cannot be null Parameter Name: path" - ODP.Net new OracleConnection "Value cannot be null Parameter Name: path" ODP.Net - 使用自定义类型参数调用存储过程抛出 ORA-06550/PLS-00306 - ODP.Net - Calling stored procedure with custom type parameter throws ORA-06550/PLS-00306
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM