在C#中利用adodb调用oracle中定义的函数,如何实现? |
|
例如一个很简单的函数:
FUNCTION testf (x IN VARCHAR2) RETURN VARCHAR2 IS BEGIN RETURN x || “-server”; END; |
|
调用存储过程,我利用下面的代码能实现:
ADODB.Command adoCmd; GeneralCommon.M_CN1.CursorLocation = ADODB.CursorLocationEnum.adUseServer; adoCmd = new ADODB.Command(); Conn.BeginTrans(); adoCmd.ActiveConnection = GeneralCommon.M_CN1; adoCmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc; adoCmd.CommandText = Proce_Name; //Ceate Input Parameter for (iCount = 0; iCount <= Para_Info.Length – 1; iCount++) { adoCmd.Parameters.Append(adoCmd.CreateParameter(“”, ADODB.DataTypeEnum.adVariant, ADODB.ParameterDirectionEnum.adParamInput, 0, null)); } //Input Parameters Value Setting for (iCount = 0; iCount <= Para_Info.Length – 1; iCount++) { adoCmd.Parameters[iCount].Value = Para_Info[iCount]; } object value = null; adoCmd.Parameters.Append(adoCmd.CreateParameter(“arg_e_code”, ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamOutput, 1, value)); adoCmd.Parameters.Append(adoCmd.CreateParameter(“arg_e_msg”, ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamOutput, 256, value)); adoCmd.Execute(out value); //Process Error Check if (adoCmd.Parameters[“arg_e_code”].Value.ToString() != “0”) { ret_Result_ErrCode =int.Parse( adoCmd.Parameters[“arg_e_code”].Value.ToString()); ret_Result_ErrMsg = (string)(adoCmd.Parameters[“arg_e_msg”].Value); Conn.RollbackTrans();//1123 sErrMessg = (string)(“Error Code : ” + ret_Result_ErrCode + “\r\n” + “Error Mesg : ” + ret_Result_ErrMsg); Gp_MsgBoxDisplay(sErrMessg, “”, “”); returnValue = false; } else { Conn.CommitTrans(); returnValue = true; } adoCmd = null; Cursor.Current = Cursors.Default; if (GeneralCommon.M_CN1.State != 0) { GeneralCommon.M_CN1.Close(); } } catch (Exception ex) { adoCmd = null; Conn.RollbackTrans(); } return returnValue; |
|
40分 |
select testf(“x”) from dual
|