如何使用Asp.net Web Api调用Oracle函数

时间:2019-01-08 05:06:03

标签: asp.net database oracle asp.net-web-api oracle-sqldeveloper

我正在一个项目上,我想使用Asp.Net Web API调用Oracle函数。目前,我正在使用StoredProcedure及其工作正常。我希望如果我的记录提交了,那么它会给我一些返回值。我的ASp.NEt Web Api代码和Oracle Function如下:

 for (int i = 0; i < user.Count; i++)
            {

                var sParameter = new List<OracleParameter>();
                sParameter.Add(new OracleParameter { ParameterName = "@CRD_COD", Value = user[i].CRD_COD });
                sParameter.Add(new OracleParameter { ParameterName = "@ITM_COD", Value = user[i].ITM_COD });
                sParameter.Add(new OracleParameter { ParameterName = "@SRL_NUM", Value = user[i].SRL_NUM });
                sParameter.Add(new OracleParameter { ParameterName = "@UOM_ABR", Value = user[i].UOM_ABR });
                sParameter.Add(new OracleParameter { ParameterName = "@QTD_RTE", Value = user[i].QTD_RTE });
                sParameter.Add(new OracleParameter { ParameterName = "@QTY_PRC", Value = user[i].QTY_PRC });
                sParameter.Add(new OracleParameter { ParameterName = "@QTN_NUM", Value = user[i].QTN_NUM });
                sParameter.Add(new OracleParameter { ParameterName = "@PMT_FLG", Value = user[i].PMT_FLG });
                sParameter.Add(new OracleParameter { ParameterName = "@TAX_FLG", Value = user[i].TAX_FLG });
                sParameter.Add(new OracleParameter { ParameterName = "@DLV_FLG", Value = user[i].DLV_FLG });                    
                result = Convert.ToInt32(ADOManager.Instance.ExecuteNonQuery("NML.AddProduct", CommandType.Text, sParameter));                
           }

这是Oracle函数

CREATE OR REPLACE FUNCTION NML.AddProduct(V_CRD_COD In varchar2,
                                        V_ITM_COD In varchar2,
                                        V_SRL_NUM In varchar2,
                                        V_UOM_ABR IN varchar2,
                                        V_QTD_RTE IN varchar2,
                                        V_QTY_PRC In varchar2,
                                        V_QTN_NUM IN varchar2,
                                        V_PMT_FLG IN varchar2,
                                        V_TAX_FLG IN varchar2,
                                        V_DLV_FLG IN varchar2
                                        )
                                        RETURN NUMBER                                      
IS

开始 如果SQL%FOUND THEN   返回(1); 其他 RETURN(1);
万一; 别人那么例外
          返回(1); END;

任何帮助将不胜感激。非常感谢

1 个答案:

答案 0 :(得分:0)

您是否尝试执行调用该函数的select语句?

.ExecuteScalar(“ SELECT NML.AddProduct(V_CRD_COD,V_ITM_COD,V_SRL_NUM,V_UOM_ABR,V_QTD_RTE,V_QTY_PRC,V_QTN_NUM,V_PMT_FLG,V_TAX_UALG,V_DLV_FLG”)