En primer lugar, no use OleDb
, período. Microsoft le dice que use un proveedor específico del proveedor. Utilice ODP.NET de Oracle.
En segundo lugar, para recuperar el conjunto de registros de Oracle SP, debe devolver refCursor
.
Editar: En este momento sabemos que sus parámetros son tablas. Para procesar esto, debe agregar p.CollectionType = OracleCollectionType.PLSQLAssociativeArray
a sus parámetros
Su código es esencialmente este:
Declare
obus_grp_id PKG_HOBS.Tnumber; -- numeric table value
ostat_c PKG_HOBS.Tnumber; -- numeric table value
ostat_msg_x PKG_HOBS.Tmsg_500; -- string table value
BEGIN
PKG_HOBS.PRC_HOBS_GET_CLIENTID(obus_grp_id, ostat_c, ostat_msg_x);
END;
Veo que ejecuta un bloqueo anónimo; no es necesario que lo haga, ya que esto le complica las cosas. Lo que debe hacer es usar vb.net para ejecutar el paquete directamente.
Conclusión: su código ORACLE actual no hace nada para enviar resultados a .NET. Elimina el bloqueo anónimo y estarás en el negocio.
Aquí está el código para procesar su tipo de trámite (leer en los comentarios)
Dim cmd As New OracleCommand("PKG_HOBS.PRC_HOBS_GET_CLIENTID", conn)
cmd.CommandType = CommandType.StoredProcedure
Dim p1 As New OracleParameter(":p1", OracleDbType.Int64, ParameterDirection.Output)
p1.CollectionType = OracleCollectionType.PLSQLAssociativeArray
p1.Size = 100 ' Declare more than you expect
' This line below is not needed for numeric types (date too???)
' p1.ArrayBindSize = New Integer(99) {}
cmd.Parameters.Add(p1)
' Add parameter 2 here - same as 1
Dim p3 As New OracleParameter(":p3", OracleDbType.Varchar2, ParameterDirection.Output)
p3.CollectionType = OracleCollectionType.PLSQLAssociativeArray
p3.Size = 100 ' Declare more than you expect
' for string data types you need to allocate space for each element
p3.ArrayBindSize = Enumerable.Repeat(500, 100).ToArray() ' get 100 elements of 500 - size of returning string
' I don't know why you have problems referencing System.Linq but if you do...
'Dim intA() As Integer = New Integer(99) {}
'For i as integer = 0 to intA.Length -1
' intA(i) = 500
'Next
cmd.Parameters.Add(p3)
conn.Open()
cmd.ExecuteNonQuery()
' Ora number is not compatible to .net types. for example integer is something
' between number(9) and (10). So, if number(10) is the type - you get Long in
' return. Therefore use "Convert"
' Also, you return arrays, so you need to process them as arrays - NOTE CHANGES
Dim oraNumbers() As OracleDecimal = CType(p1.Value, OracleDecimal())
Dim myP1Values(oraNumbers.Length - 1) As Long
For i as Integer = 0 To oraNumbers.Length - 1
myP1Values(i) = Convert.ToInt64(oraNumbers(i).Value)
Next
oraNumbers = CType(p2.Value, OracleDecimal())
Dim myP2Values(oraNumbers.Length - 1) As Long
For i as Integer = 0 To oraNumbers.Length - 1
myP2Values(i) = Convert.ToInt64(oraNumbers(i).Value)
Next
Dim oraStrings() As OracleString= CType(p3.Value, OracleString())
Dim myP3Values(oraStrings.Length - 1) As String
For i as Integer = 0 To oraStrings.Length - 1
myP3Values(i) = oraStrings(i).Value
Next
Y esta es la parte más importante
La parte más importante es cómo llena su tipo declarado. Tomemos
TYPE Tnumber IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
v_num Tnumber;
v_num(1) := 1234567890;
v_num(2) := 2345678901;
v_num(3) := 3456789012;
Esto (arriba) funcionará. Pero esto fallará:
v_num(0) := 1234567890;
v_num(1) := 2345678901;
v_num(2) := 3456789012;
Y finalmente, esto funcionará con una condición
v_num(2) := 1234567890;
v_num(3) := 2345678901;
v_num(4) := 3456789012;
Aquí obtendremos 4 miembros en p1.Value
pero bajo el índice 0
tendrás oracle null
. Por lo tanto, deberá tratarlo aquí (si tiene tal condición)
' instead of this
myP2Values(i) = Convert.ToInt64(oraNumbers(i).Value)
' you will need first to check
If oraNumbers(i).IsNull Then
. . . .
Entonces, lo principal aquí es, ¿CUÁL es el índice de su tabla pl/sql? Debe comenzar desde algo más grande que 0
, y preferiblemente de 1
. Y si tiene un índice con números omitidos, es decir, 2,4,6,8
, todos esos espacios serán parte de la matriz oracle que regresa y habrá oracle null
en ellos
Aquí hay alguna referencia