How to pass boolean parameter to Oracle procedure C#

前端 未结 2 901
感情败类
感情败类 2020-12-12 03:26

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         


        
相关标签:
2条回答
  • 2020-12-12 03:33

    Consider the following procedure as example

    CREATE OR REPLACE PROCEDURE my_procedure
    (
       condition NUMBER,...
    

    In C#, add parameter

    cmd.Parameters.Add("@condition", OracleDbType.Char).Value = myObject.isCondition ? 1 : 0;
    
    0 讨论(0)
  • 2020-12-12 03:49

    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 does not support Boolean data type. Just use 1 or 0 as a char value to persist it.

    For Sample:

    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();
    
    0 讨论(0)
提交回复
热议问题