调用oracle存储函数

时间:2013-09-01 08:34:04

标签: c# oracle

我尝试调用我的oracle函数,但由于某种原因,我得到了它的结果。

这是我的C#代码:

using (OracleConnection _conn = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.20.190.2)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=DBIDB)));User Id=blng;Password=blng;"))
{
    using (OracleCommand cmd = new OracleCommand())
    {
        _conn.Open();

        cmd.Connection = _conn;
        cmd.CommandType = System.Data.CommandType.StoredProcedure;

        cmd.CommandText = "PKG_update_switch.checkexistsinswitch";
        cmd.Parameters.Add("phone", OracleDbType.Varchar2, ParameterDirection.Input).Value = phoneToQuery;
        cmd.Parameters.Add("res", OracleDbType.Int32, ParameterDirection.ReturnValue);
        cmd.ExecuteNonQuery();

        result = cmd.Parameters["res"].Value.ToString();
        Debug.WriteLine("---" + result);

        if (result.Equals("null"))
            message = "Didnt find number";
        else
            message = "Found " + phoneToQuery + " in " + result;
        MessageBox.Show(message, "Check Phone Exists",
        MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
        _conn.Close();
    }
}

结果我总是0,女巫是不可能的。

Oracle功能:

function checkExistsInSwitch(phone in varchar2) RETURN integer is
  tmp varchar2(100):='';
  begin
    for t in (select c.re_collection_id from re_collection_values c where c.start_range = phone)
        loop
         ----- check that the number is from folder number 2
         begin
        select o.network_identifier into tmp from operators o where o.switch_folder_id = t.re_collection_id;
        return 11;--tmp;
      exception 
        when others then
          null;
      end;
    end loop;
return 11;--'';
end;

这是非常有用的,对于存储过程我得到了很好的结果,这只发生在我的存储函数中。

0 个答案:

没有答案