c#使用odp调用oracle带返回值的存储过程

返回值为varchar2类型的示例:

public string QueryForLastestIndicatorValue(string personId, string crowdGroup)
        {
            OracleParameter[] parms = new OracleParameter[]
                            {
                                new OracleParameter(":个人id_In", OracleDbType.Varchar2),
                                new OracleParameter(":人群码集合_In", OracleDbType.Varchar2),
                                new OracleParameter(":结果_Out", OracleDbType.Varchar2,ParameterDirection.Output){Size=255}
                            };

            parms[0].Value = personId;
            parms[1].Value = crowdGroup;
            int k = OracleHelper.ExecuteNonQuery(OracleHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "P_居民关注指标_QUERY2", parms);
            
            object value = parms[2].Value;
            return (value == null || value.ToString().Equals("null")) ? string.Empty : value.ToString();
        }

 

 

返回值为cursor(dataset)的示例

DataSet ds = new DataSet();

            OracleParameter[] parms = new OracleParameter[]
                            {
                                new OracleParameter(":个人id_In", OracleDbType.Varchar2),
                                new OracleParameter(":指标名称_In", OracleDbType.Varchar2),
                                new OracleParameter(":指标名称_In", OracleDbType.RefCursor,ParameterDirection.Output),
                            };

            parms[0].Value = personId;
            parms[1].Value = attentionTarget;
            OracleConnection connection = new OracleConnection(OracleHelper.ConnectionStringLocalTransaction);
            OracleCommand cmd = new OracleCommand("p_居民关注指标明细_Query", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            OracleDataAdapter adapter = new OracleDataAdapter(cmd);
            connection.Open();
            if (parms != null && parms.Length > 0)
                adapter.SelectCommand.Parameters.AddRange(parms.ToArray());

            OracleDataReader read = cmd.ExecuteReader(CommandBehavior.SchemaOnly);//ODP驱动时如果查询的字段有参数则会报ORA-01036: 非法的变量名/编号错误,先执行以下ExecuteReader可避免
            read.Close();
            read.Dispose();
            connection.Close();
            adapter.Fill(ds);

            return ds;
 

 

你可能感兴趣的:(oracle,C++,c,C#)