ORA-06502:PL / SQL:数字或值错误ORA-06512:位于“ JOHN.GET_USERS_EMAIL”的第7行ORA-06512:第1行
当我在SQL Developer中运行过程并在应用程序中使用值时,它可以正常工作。当我运行VB.Net代码时,出现异常(如上所示)
我不知道我做错了什么。 (Oracle过程不是由我编写的。它是由另一个不再在这里工作的人编写的。)>
Oracle中的步骤
create or replace PROCEDURE "GET_USERS_EMAIL" ( User_Email_P OUT VARCHAR, Employee_P IN VARCHAR ) As Begin SELECT USER_EMAIL INTO User_Email_P FROM EMPLOYEE WHERE USER_ID = Employee_P; end;
VB.Net中的代码
Public Function Get_A_Users_Email(ByVal strEmpId As String) As String Try Dim rValue As String = "" Dim strSQL As String = "JOHN.GET_USERS_EMAIL" Dim cmd As OracleCommand = dba.CreateStoredProcCommand(strSQL) cmd.BindByName = True Dim oracleParameter(1) As OracleParameter oracleParameter(0) = New OracleParameter() oracleParameter(1) = New OracleParameter() strEmpId = UCase(strEmpId.Trim()) With cmd oracleParameter(0) = cmd.Parameters.Add(name:="User_Email_P", dbType:=OracleDbType.Varchar2, direction:=ParameterDirection.Output) oracleParameter(1) = cmd.Parameters.Add(name:="Employee_P", dbType:=OracleDbType.Varchar2, val:=strEmpId, ParameterDirection.Input) End With dba.ExecuteScaler(cmd) If String.IsNullOrEmpty(cmd.Parameters("User_Email_P").Value.ToString) = True Then rValue = 0 Else rValue = cmd.Parameters("User_Email_P").Value.ToString End If Return rValue Catch ex As Exception Dim Err As New App_Errors("App_Users", "Get_A_Users_Email", ex) Return Nothing End Try End Function Public Function ExecuteScaler(ByVal cmd As OracleCommand) As String ' the value tobe return ... Dim value As String = "" Dim oValue As Object Dim bValue As Boolean = False ' execute command ... Try ' open connection ... cmd.Connection.Open() Catch ex As Exception MsgBox("Unable to establish a connection to CFR database." & ex.ToString, MsgBoxStyle.Critical) Return value = "" Exit Function End Try Try ' execute command ... convert type in the case of return value null ... oValue = cmd.ExecuteScalar bValue = Convert.IsDBNull(oValue) If Not (bValue) Then value = CType(oValue, String) Else value = "" End If Catch ex As Exception ' rethrow error ... ' Dim Err As New App_Errors("Data_Access_Class", "ExecuteScalar", ex) Throw New Exception(ex.InnerException.ToString, ex) Finally cmd.Connection.Close() End Try Return value End Function Public Function CreateStoredProcCommand(ByVal cmdtext As String) As OracleCommand Dim Cmd As New OracleCommand ' command object ... ' create command ... With Cmd .Connection = Conn .CommandText = cmdtext .CommandType = CommandType.StoredProcedure End With Return Cmd End Function
这里是表的DDL。
CREATE TABLE "JOHN"."EMPLOYEE" ( "EMPLOYEE_NUMBER" NUMBER(9,0), "LOCATION_CODE" VARCHAR2(4 BYTE), "SECURITY_LEVEL" NUMBER(2,0), "DATE_LAST_UPDATE" DATE, "DATE_SECURITY_ASSIGNED" DATE, "LAST_PASSWORD_DATE" DATE, "CURRENT_PASSWORD" VARCHAR2(8 BYTE), "FIRST_NAME" VARCHAR2(20 BYTE), "MIDDLE_INITIAL" VARCHAR2(1 BYTE), "LAST_NAME" VARCHAR2(30 BYTE), "USER_ID" VARCHAR2(8 BYTE), "USER_TYPE" CHAR(1 BYTE), "INACTIVE_DATE" DATE, "SECURITY_ASSIGNED_BY" VARCHAR2(8 BYTE), "PASSWORD_EXPIRATION_DATE" DATE, "STATUS_CODE" NUMBER(2,0), "ACCOUNT_LOCKED" VARCHAR2(1 BYTE), "UPDATE_PASS_ON_SIGNON" VARCHAR2(1 BYTE), "USER_EMAIL" VARCHAR2(30 BYTE))
[请注意,DDL,存储过程和VB.Net代码是以前的开发人员留下的。我正在将Microsoft的Oracle驱动程序的实现替换为ODP.Net。除此之外,代码上没有任何其他更改。
ORA-06502:PL / SQL:数字或值错误ORA-06512:在“ JOHN.GET_USERS_EMAIL”,第7行ORA-06512:在第1行当我在SQL Developer中运行过程并在应用程序中使用值时,它的工作原理...
将数据库对象保留在使用它们的方法的本地。这样,您可以控制何时将它们关闭和处置。连接和命令可能包含非托管代码,需要使用它们各自的.Dispose
方法来释放它们。在此示例中,即使有错误,Using...End Using
块也会为您处理。