NullReferenceException Thrown from Oracle.DataAccess.dll
up vote
2
down vote
favorite
I am having a problem using Oracle Data Provider with .NET . I am using an array of a User-Defined Objects as an IN parameter to a stored procedure. I have added the database schema to Visual Studio 2015 Server Explorer and generated the Custom Type Class corresponding to the UDT I am using. I am using the following code to call the procedure.
OracleCommand cmd = DataBase.Connection.CreateCommand();
cmd.CommandText = "MYPROCEDURE";
cmd.CommandType = CommandType.StoredProcedure;
cmd.BindByName = true;
MY_TYPE arr = new MY_TYPE[2];
arr[0] = new MY_TYPE(1, 2);
arr[1] = new MY_TYPE(3, 4);
OracleParameter pEntries = new OracleParameter();
pEntries.ParameterName = "ENTRIES";
pEntries.Direction = ParameterDirection.Input;
pEntries.OracleDbType = OracleDbType.Array;
pEntries.UdtTypeName = "MY_TYPE";
pEntries.Value = arr;
pEntries.Size = 2;
cmd.Parameters.Add(pEntries);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
The problem is it throws a NullReferenceException
from within the Oracle Driver, Specifically from Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value, Object statusArray)
.
Notes:
- The connection is tested with other procedure calls and it is working properly.
- I have made sure through the debugger that the array elements are not null and their "
IsNull
" property is set to false, and that their members are not null and each members "IsNull
" property is set to false.
The UDT is defined as follows:
CREATE OR REPLACE TYPE my_type AS OBJECT
(
id NUMBER;
value NUMBER;
)
The procedure takes a custom collection type defined as follows:
CREATE OR REPLACE my_type_varray AS VARRAY(50) OF my_type
The parameter's settings are the only accepted settings, I have tried creating a custom type for a collection but it generates an error saying "wrong number or types of arguments in call to MYPROCEDURE", these setting generate the NullReferenceException, which means it accepted the parameters and moved on to process them.
For sake of simplicity I have omitted a lot of the code, and I have written it manually. But I will post it if I had to.
Additional info:
stacktrace:
Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value, Object statusArray)
at Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value)
at Oracle.DataAccess.Client.OracleParameter.SetUDTFromArray(OracleConnection conn, Object array, Int32 i)
at Oracle.DataAccess.Client.OracleParameter.PreBind_Collection(OracleConnection conn)
at Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize, Boolean bIsFromEF, Boolean bIsSelectStmt) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
I have created a simple test procedure called TEST
, which takes a single instance of the UDT. The procedure is defined as follows:
FUNCTION test(obj in MY_TYPE) RETURN NUMBER IS
BEGIN
RETURN obj.id*obj.value;
END;
The code for calling the procedure is :
OracleCommand cmd = DataBase.Connection.CreateCommand();
cmd.CommandText = "TEST";
cmd.CommandType = CommandType.StoredProcedure;
cmd.BindByName = true;
MY_TYPE obj = new MY_TYPE(2, 3);
OracleParameter pEntries = new OracleParameter();
Entries.ParameterName = "obj";
pEntries.Direction = ParameterDirection.Input;
pEntries.OracleDbType = OracleDbType.Object;
pEntries.UdtTypeName = "MY_TYPE";
pEntries.Value = obj;
cmd.Parameters.Add(pEntries);
// -- omitted some code for the return value parameter
cmd.Connection.Open();
cmd.ExecuteNonQuery();
The previous code worked properly and the result was 6.
c# oracle nullreferenceexception odp.net user-defined-types
New contributor
|
show 1 more comment
up vote
2
down vote
favorite
I am having a problem using Oracle Data Provider with .NET . I am using an array of a User-Defined Objects as an IN parameter to a stored procedure. I have added the database schema to Visual Studio 2015 Server Explorer and generated the Custom Type Class corresponding to the UDT I am using. I am using the following code to call the procedure.
OracleCommand cmd = DataBase.Connection.CreateCommand();
cmd.CommandText = "MYPROCEDURE";
cmd.CommandType = CommandType.StoredProcedure;
cmd.BindByName = true;
MY_TYPE arr = new MY_TYPE[2];
arr[0] = new MY_TYPE(1, 2);
arr[1] = new MY_TYPE(3, 4);
OracleParameter pEntries = new OracleParameter();
pEntries.ParameterName = "ENTRIES";
pEntries.Direction = ParameterDirection.Input;
pEntries.OracleDbType = OracleDbType.Array;
pEntries.UdtTypeName = "MY_TYPE";
pEntries.Value = arr;
pEntries.Size = 2;
cmd.Parameters.Add(pEntries);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
The problem is it throws a NullReferenceException
from within the Oracle Driver, Specifically from Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value, Object statusArray)
.
Notes:
- The connection is tested with other procedure calls and it is working properly.
- I have made sure through the debugger that the array elements are not null and their "
IsNull
" property is set to false, and that their members are not null and each members "IsNull
" property is set to false.
The UDT is defined as follows:
CREATE OR REPLACE TYPE my_type AS OBJECT
(
id NUMBER;
value NUMBER;
)
The procedure takes a custom collection type defined as follows:
CREATE OR REPLACE my_type_varray AS VARRAY(50) OF my_type
The parameter's settings are the only accepted settings, I have tried creating a custom type for a collection but it generates an error saying "wrong number or types of arguments in call to MYPROCEDURE", these setting generate the NullReferenceException, which means it accepted the parameters and moved on to process them.
For sake of simplicity I have omitted a lot of the code, and I have written it manually. But I will post it if I had to.
Additional info:
stacktrace:
Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value, Object statusArray)
at Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value)
at Oracle.DataAccess.Client.OracleParameter.SetUDTFromArray(OracleConnection conn, Object array, Int32 i)
at Oracle.DataAccess.Client.OracleParameter.PreBind_Collection(OracleConnection conn)
at Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize, Boolean bIsFromEF, Boolean bIsSelectStmt) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
I have created a simple test procedure called TEST
, which takes a single instance of the UDT. The procedure is defined as follows:
FUNCTION test(obj in MY_TYPE) RETURN NUMBER IS
BEGIN
RETURN obj.id*obj.value;
END;
The code for calling the procedure is :
OracleCommand cmd = DataBase.Connection.CreateCommand();
cmd.CommandText = "TEST";
cmd.CommandType = CommandType.StoredProcedure;
cmd.BindByName = true;
MY_TYPE obj = new MY_TYPE(2, 3);
OracleParameter pEntries = new OracleParameter();
Entries.ParameterName = "obj";
pEntries.Direction = ParameterDirection.Input;
pEntries.OracleDbType = OracleDbType.Object;
pEntries.UdtTypeName = "MY_TYPE";
pEntries.Value = obj;
cmd.Parameters.Add(pEntries);
// -- omitted some code for the return value parameter
cmd.Connection.Open();
cmd.ExecuteNonQuery();
The previous code worked properly and the result was 6.
c# oracle nullreferenceexception odp.net user-defined-types
New contributor
1
Which line of your code is it failing on? I understand the exception is within the Oracle assembly, but it would be useful to know whether it's reachedExecuteNonQuery
or not.
– Jon Skeet
Nov 7 at 7:33
The Exception is thrown from within the ExecuteNonQuery.
– Ali A. Ismaeel
Nov 7 at 7:35
1
Please add the stack trace into the post. Also, if you could add whether you have any other calls working with UDTs, that would be useful. (Does this UDT work elsewhere? Do you have different UDTs that work?)
– Jon Skeet
Nov 7 at 7:39
I have no other working calls with the same udt
– Ali A. Ismaeel
Nov 7 at 7:47
Do you have this working with other UDTs though? If it's this UDT that is causing problems, have you experimented with using it in simpler scenarios (e.g. without arrays)? What's in the UDT, and have you tried diagnosing this by making the UDT simpler and simpler?
– Jon Skeet
Nov 7 at 8:01
|
show 1 more comment
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am having a problem using Oracle Data Provider with .NET . I am using an array of a User-Defined Objects as an IN parameter to a stored procedure. I have added the database schema to Visual Studio 2015 Server Explorer and generated the Custom Type Class corresponding to the UDT I am using. I am using the following code to call the procedure.
OracleCommand cmd = DataBase.Connection.CreateCommand();
cmd.CommandText = "MYPROCEDURE";
cmd.CommandType = CommandType.StoredProcedure;
cmd.BindByName = true;
MY_TYPE arr = new MY_TYPE[2];
arr[0] = new MY_TYPE(1, 2);
arr[1] = new MY_TYPE(3, 4);
OracleParameter pEntries = new OracleParameter();
pEntries.ParameterName = "ENTRIES";
pEntries.Direction = ParameterDirection.Input;
pEntries.OracleDbType = OracleDbType.Array;
pEntries.UdtTypeName = "MY_TYPE";
pEntries.Value = arr;
pEntries.Size = 2;
cmd.Parameters.Add(pEntries);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
The problem is it throws a NullReferenceException
from within the Oracle Driver, Specifically from Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value, Object statusArray)
.
Notes:
- The connection is tested with other procedure calls and it is working properly.
- I have made sure through the debugger that the array elements are not null and their "
IsNull
" property is set to false, and that their members are not null and each members "IsNull
" property is set to false.
The UDT is defined as follows:
CREATE OR REPLACE TYPE my_type AS OBJECT
(
id NUMBER;
value NUMBER;
)
The procedure takes a custom collection type defined as follows:
CREATE OR REPLACE my_type_varray AS VARRAY(50) OF my_type
The parameter's settings are the only accepted settings, I have tried creating a custom type for a collection but it generates an error saying "wrong number or types of arguments in call to MYPROCEDURE", these setting generate the NullReferenceException, which means it accepted the parameters and moved on to process them.
For sake of simplicity I have omitted a lot of the code, and I have written it manually. But I will post it if I had to.
Additional info:
stacktrace:
Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value, Object statusArray)
at Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value)
at Oracle.DataAccess.Client.OracleParameter.SetUDTFromArray(OracleConnection conn, Object array, Int32 i)
at Oracle.DataAccess.Client.OracleParameter.PreBind_Collection(OracleConnection conn)
at Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize, Boolean bIsFromEF, Boolean bIsSelectStmt) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
I have created a simple test procedure called TEST
, which takes a single instance of the UDT. The procedure is defined as follows:
FUNCTION test(obj in MY_TYPE) RETURN NUMBER IS
BEGIN
RETURN obj.id*obj.value;
END;
The code for calling the procedure is :
OracleCommand cmd = DataBase.Connection.CreateCommand();
cmd.CommandText = "TEST";
cmd.CommandType = CommandType.StoredProcedure;
cmd.BindByName = true;
MY_TYPE obj = new MY_TYPE(2, 3);
OracleParameter pEntries = new OracleParameter();
Entries.ParameterName = "obj";
pEntries.Direction = ParameterDirection.Input;
pEntries.OracleDbType = OracleDbType.Object;
pEntries.UdtTypeName = "MY_TYPE";
pEntries.Value = obj;
cmd.Parameters.Add(pEntries);
// -- omitted some code for the return value parameter
cmd.Connection.Open();
cmd.ExecuteNonQuery();
The previous code worked properly and the result was 6.
c# oracle nullreferenceexception odp.net user-defined-types
New contributor
I am having a problem using Oracle Data Provider with .NET . I am using an array of a User-Defined Objects as an IN parameter to a stored procedure. I have added the database schema to Visual Studio 2015 Server Explorer and generated the Custom Type Class corresponding to the UDT I am using. I am using the following code to call the procedure.
OracleCommand cmd = DataBase.Connection.CreateCommand();
cmd.CommandText = "MYPROCEDURE";
cmd.CommandType = CommandType.StoredProcedure;
cmd.BindByName = true;
MY_TYPE arr = new MY_TYPE[2];
arr[0] = new MY_TYPE(1, 2);
arr[1] = new MY_TYPE(3, 4);
OracleParameter pEntries = new OracleParameter();
pEntries.ParameterName = "ENTRIES";
pEntries.Direction = ParameterDirection.Input;
pEntries.OracleDbType = OracleDbType.Array;
pEntries.UdtTypeName = "MY_TYPE";
pEntries.Value = arr;
pEntries.Size = 2;
cmd.Parameters.Add(pEntries);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
The problem is it throws a NullReferenceException
from within the Oracle Driver, Specifically from Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value, Object statusArray)
.
Notes:
- The connection is tested with other procedure calls and it is working properly.
- I have made sure through the debugger that the array elements are not null and their "
IsNull
" property is set to false, and that their members are not null and each members "IsNull
" property is set to false.
The UDT is defined as follows:
CREATE OR REPLACE TYPE my_type AS OBJECT
(
id NUMBER;
value NUMBER;
)
The procedure takes a custom collection type defined as follows:
CREATE OR REPLACE my_type_varray AS VARRAY(50) OF my_type
The parameter's settings are the only accepted settings, I have tried creating a custom type for a collection but it generates an error saying "wrong number or types of arguments in call to MYPROCEDURE", these setting generate the NullReferenceException, which means it accepted the parameters and moved on to process them.
For sake of simplicity I have omitted a lot of the code, and I have written it manually. But I will post it if I had to.
Additional info:
stacktrace:
Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value, Object statusArray)
at Oracle.DataAccess.Types.OracleUdt.SetValue(OracleConnection con, IntPtr pUdt, Int32 attrIndex, Object value)
at Oracle.DataAccess.Client.OracleParameter.SetUDTFromArray(OracleConnection conn, Object array, Int32 i)
at Oracle.DataAccess.Client.OracleParameter.PreBind_Collection(OracleConnection conn)
at Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize, Boolean bIsFromEF, Boolean bIsSelectStmt) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
I have created a simple test procedure called TEST
, which takes a single instance of the UDT. The procedure is defined as follows:
FUNCTION test(obj in MY_TYPE) RETURN NUMBER IS
BEGIN
RETURN obj.id*obj.value;
END;
The code for calling the procedure is :
OracleCommand cmd = DataBase.Connection.CreateCommand();
cmd.CommandText = "TEST";
cmd.CommandType = CommandType.StoredProcedure;
cmd.BindByName = true;
MY_TYPE obj = new MY_TYPE(2, 3);
OracleParameter pEntries = new OracleParameter();
Entries.ParameterName = "obj";
pEntries.Direction = ParameterDirection.Input;
pEntries.OracleDbType = OracleDbType.Object;
pEntries.UdtTypeName = "MY_TYPE";
pEntries.Value = obj;
cmd.Parameters.Add(pEntries);
// -- omitted some code for the return value parameter
cmd.Connection.Open();
cmd.ExecuteNonQuery();
The previous code worked properly and the result was 6.
c# oracle nullreferenceexception odp.net user-defined-types
c# oracle nullreferenceexception odp.net user-defined-types
New contributor
New contributor
edited Nov 7 at 8:16
New contributor
asked Nov 7 at 7:28
Ali A. Ismaeel
112
112
New contributor
New contributor
1
Which line of your code is it failing on? I understand the exception is within the Oracle assembly, but it would be useful to know whether it's reachedExecuteNonQuery
or not.
– Jon Skeet
Nov 7 at 7:33
The Exception is thrown from within the ExecuteNonQuery.
– Ali A. Ismaeel
Nov 7 at 7:35
1
Please add the stack trace into the post. Also, if you could add whether you have any other calls working with UDTs, that would be useful. (Does this UDT work elsewhere? Do you have different UDTs that work?)
– Jon Skeet
Nov 7 at 7:39
I have no other working calls with the same udt
– Ali A. Ismaeel
Nov 7 at 7:47
Do you have this working with other UDTs though? If it's this UDT that is causing problems, have you experimented with using it in simpler scenarios (e.g. without arrays)? What's in the UDT, and have you tried diagnosing this by making the UDT simpler and simpler?
– Jon Skeet
Nov 7 at 8:01
|
show 1 more comment
1
Which line of your code is it failing on? I understand the exception is within the Oracle assembly, but it would be useful to know whether it's reachedExecuteNonQuery
or not.
– Jon Skeet
Nov 7 at 7:33
The Exception is thrown from within the ExecuteNonQuery.
– Ali A. Ismaeel
Nov 7 at 7:35
1
Please add the stack trace into the post. Also, if you could add whether you have any other calls working with UDTs, that would be useful. (Does this UDT work elsewhere? Do you have different UDTs that work?)
– Jon Skeet
Nov 7 at 7:39
I have no other working calls with the same udt
– Ali A. Ismaeel
Nov 7 at 7:47
Do you have this working with other UDTs though? If it's this UDT that is causing problems, have you experimented with using it in simpler scenarios (e.g. without arrays)? What's in the UDT, and have you tried diagnosing this by making the UDT simpler and simpler?
– Jon Skeet
Nov 7 at 8:01
1
1
Which line of your code is it failing on? I understand the exception is within the Oracle assembly, but it would be useful to know whether it's reached
ExecuteNonQuery
or not.– Jon Skeet
Nov 7 at 7:33
Which line of your code is it failing on? I understand the exception is within the Oracle assembly, but it would be useful to know whether it's reached
ExecuteNonQuery
or not.– Jon Skeet
Nov 7 at 7:33
The Exception is thrown from within the ExecuteNonQuery.
– Ali A. Ismaeel
Nov 7 at 7:35
The Exception is thrown from within the ExecuteNonQuery.
– Ali A. Ismaeel
Nov 7 at 7:35
1
1
Please add the stack trace into the post. Also, if you could add whether you have any other calls working with UDTs, that would be useful. (Does this UDT work elsewhere? Do you have different UDTs that work?)
– Jon Skeet
Nov 7 at 7:39
Please add the stack trace into the post. Also, if you could add whether you have any other calls working with UDTs, that would be useful. (Does this UDT work elsewhere? Do you have different UDTs that work?)
– Jon Skeet
Nov 7 at 7:39
I have no other working calls with the same udt
– Ali A. Ismaeel
Nov 7 at 7:47
I have no other working calls with the same udt
– Ali A. Ismaeel
Nov 7 at 7:47
Do you have this working with other UDTs though? If it's this UDT that is causing problems, have you experimented with using it in simpler scenarios (e.g. without arrays)? What's in the UDT, and have you tried diagnosing this by making the UDT simpler and simpler?
– Jon Skeet
Nov 7 at 8:01
Do you have this working with other UDTs though? If it's this UDT that is causing problems, have you experimented with using it in simpler scenarios (e.g. without arrays)? What's in the UDT, and have you tried diagnosing this by making the UDT simpler and simpler?
– Jon Skeet
Nov 7 at 8:01
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
As far as I know you cannot use VARRAY
as parameter. The only supported collection type are Associative Arrays (Index-By Tables), e.g.
TYPE TArrayOfNumber IS TABLE OF NUMBER INDEX BY INTEGER;
So, you would have to pass two parameters, one array of id
and one array for value
. Then you can create the OBJECT type within PL/SQL
PROCEDURE MYPROCEDURE(IdList IN TArrayOfNumber, ValueList IN TArrayOfNumber ) IS
my_type_list my_type_varray;
BEGIN
FOR i IN IdList.FIRST..IdList.LAST LOOP
my_type_list(i) := my_type(IdList(i), ValueList(i));
END LOOP;
...
END;
and in C# like this:
var par1 = cmd.Parameters.Add("IdList ", OracleDbType.Int16, ParameterDirection.Input);
par1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par1.Value = new int { 1, 2};
par1.Size = 2:
var par2 = cmd.Parameters.Add("ValueList ", OracleDbType.Int16, ParameterDirection.Input);
par2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par2.Value = new int { 3, 4};
par2.Size = 2:
I tried to call this procedure using Java and it worked properly. Even though it uses varray. If you mean I cannot user varray in C#, then this makes more sense. If you could post some code of a call to a stored procedure which takes an associative array of UDT as a parameter I would be very thankful.
– Ali A. Ismaeel
Nov 7 at 8:20
You can pass one value of a UDT or a list of simple data types (e.g NUMBER, VARCHAR2, etc.) which have to be declared as Associative Array in PL/SQL. But you cannot pass a list of UDT values.
– Wernfried Domscheit
Nov 7 at 8:46
I have successfully passed a varray of UDT using Java. So I suppose the restriction on passing a varray of UDT does not come from the database itself, but from ODP. However, there is an OracleDbType called Array. It must have some use. I have read the relevant documentation from Oracle and I did not find anything that implies that I cannot pass a varray of UDT.
– Ali A. Ismaeel
Nov 7 at 9:40
I found this OracleDbType Enumeration Type.OracleDbType.Array
was not available in earlier releases, looks like Oracle added this type. So, my statement "You can use only Associative Array" seems to be wrong meanwhile. However, I assume it is still valid to say "You can pass one value of a UDT or a list of simple data types"
– Wernfried Domscheit
Nov 7 at 10:09
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
As far as I know you cannot use VARRAY
as parameter. The only supported collection type are Associative Arrays (Index-By Tables), e.g.
TYPE TArrayOfNumber IS TABLE OF NUMBER INDEX BY INTEGER;
So, you would have to pass two parameters, one array of id
and one array for value
. Then you can create the OBJECT type within PL/SQL
PROCEDURE MYPROCEDURE(IdList IN TArrayOfNumber, ValueList IN TArrayOfNumber ) IS
my_type_list my_type_varray;
BEGIN
FOR i IN IdList.FIRST..IdList.LAST LOOP
my_type_list(i) := my_type(IdList(i), ValueList(i));
END LOOP;
...
END;
and in C# like this:
var par1 = cmd.Parameters.Add("IdList ", OracleDbType.Int16, ParameterDirection.Input);
par1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par1.Value = new int { 1, 2};
par1.Size = 2:
var par2 = cmd.Parameters.Add("ValueList ", OracleDbType.Int16, ParameterDirection.Input);
par2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par2.Value = new int { 3, 4};
par2.Size = 2:
I tried to call this procedure using Java and it worked properly. Even though it uses varray. If you mean I cannot user varray in C#, then this makes more sense. If you could post some code of a call to a stored procedure which takes an associative array of UDT as a parameter I would be very thankful.
– Ali A. Ismaeel
Nov 7 at 8:20
You can pass one value of a UDT or a list of simple data types (e.g NUMBER, VARCHAR2, etc.) which have to be declared as Associative Array in PL/SQL. But you cannot pass a list of UDT values.
– Wernfried Domscheit
Nov 7 at 8:46
I have successfully passed a varray of UDT using Java. So I suppose the restriction on passing a varray of UDT does not come from the database itself, but from ODP. However, there is an OracleDbType called Array. It must have some use. I have read the relevant documentation from Oracle and I did not find anything that implies that I cannot pass a varray of UDT.
– Ali A. Ismaeel
Nov 7 at 9:40
I found this OracleDbType Enumeration Type.OracleDbType.Array
was not available in earlier releases, looks like Oracle added this type. So, my statement "You can use only Associative Array" seems to be wrong meanwhile. However, I assume it is still valid to say "You can pass one value of a UDT or a list of simple data types"
– Wernfried Domscheit
Nov 7 at 10:09
add a comment |
up vote
0
down vote
As far as I know you cannot use VARRAY
as parameter. The only supported collection type are Associative Arrays (Index-By Tables), e.g.
TYPE TArrayOfNumber IS TABLE OF NUMBER INDEX BY INTEGER;
So, you would have to pass two parameters, one array of id
and one array for value
. Then you can create the OBJECT type within PL/SQL
PROCEDURE MYPROCEDURE(IdList IN TArrayOfNumber, ValueList IN TArrayOfNumber ) IS
my_type_list my_type_varray;
BEGIN
FOR i IN IdList.FIRST..IdList.LAST LOOP
my_type_list(i) := my_type(IdList(i), ValueList(i));
END LOOP;
...
END;
and in C# like this:
var par1 = cmd.Parameters.Add("IdList ", OracleDbType.Int16, ParameterDirection.Input);
par1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par1.Value = new int { 1, 2};
par1.Size = 2:
var par2 = cmd.Parameters.Add("ValueList ", OracleDbType.Int16, ParameterDirection.Input);
par2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par2.Value = new int { 3, 4};
par2.Size = 2:
I tried to call this procedure using Java and it worked properly. Even though it uses varray. If you mean I cannot user varray in C#, then this makes more sense. If you could post some code of a call to a stored procedure which takes an associative array of UDT as a parameter I would be very thankful.
– Ali A. Ismaeel
Nov 7 at 8:20
You can pass one value of a UDT or a list of simple data types (e.g NUMBER, VARCHAR2, etc.) which have to be declared as Associative Array in PL/SQL. But you cannot pass a list of UDT values.
– Wernfried Domscheit
Nov 7 at 8:46
I have successfully passed a varray of UDT using Java. So I suppose the restriction on passing a varray of UDT does not come from the database itself, but from ODP. However, there is an OracleDbType called Array. It must have some use. I have read the relevant documentation from Oracle and I did not find anything that implies that I cannot pass a varray of UDT.
– Ali A. Ismaeel
Nov 7 at 9:40
I found this OracleDbType Enumeration Type.OracleDbType.Array
was not available in earlier releases, looks like Oracle added this type. So, my statement "You can use only Associative Array" seems to be wrong meanwhile. However, I assume it is still valid to say "You can pass one value of a UDT or a list of simple data types"
– Wernfried Domscheit
Nov 7 at 10:09
add a comment |
up vote
0
down vote
up vote
0
down vote
As far as I know you cannot use VARRAY
as parameter. The only supported collection type are Associative Arrays (Index-By Tables), e.g.
TYPE TArrayOfNumber IS TABLE OF NUMBER INDEX BY INTEGER;
So, you would have to pass two parameters, one array of id
and one array for value
. Then you can create the OBJECT type within PL/SQL
PROCEDURE MYPROCEDURE(IdList IN TArrayOfNumber, ValueList IN TArrayOfNumber ) IS
my_type_list my_type_varray;
BEGIN
FOR i IN IdList.FIRST..IdList.LAST LOOP
my_type_list(i) := my_type(IdList(i), ValueList(i));
END LOOP;
...
END;
and in C# like this:
var par1 = cmd.Parameters.Add("IdList ", OracleDbType.Int16, ParameterDirection.Input);
par1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par1.Value = new int { 1, 2};
par1.Size = 2:
var par2 = cmd.Parameters.Add("ValueList ", OracleDbType.Int16, ParameterDirection.Input);
par2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par2.Value = new int { 3, 4};
par2.Size = 2:
As far as I know you cannot use VARRAY
as parameter. The only supported collection type are Associative Arrays (Index-By Tables), e.g.
TYPE TArrayOfNumber IS TABLE OF NUMBER INDEX BY INTEGER;
So, you would have to pass two parameters, one array of id
and one array for value
. Then you can create the OBJECT type within PL/SQL
PROCEDURE MYPROCEDURE(IdList IN TArrayOfNumber, ValueList IN TArrayOfNumber ) IS
my_type_list my_type_varray;
BEGIN
FOR i IN IdList.FIRST..IdList.LAST LOOP
my_type_list(i) := my_type(IdList(i), ValueList(i));
END LOOP;
...
END;
and in C# like this:
var par1 = cmd.Parameters.Add("IdList ", OracleDbType.Int16, ParameterDirection.Input);
par1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par1.Value = new int { 1, 2};
par1.Size = 2:
var par2 = cmd.Parameters.Add("ValueList ", OracleDbType.Int16, ParameterDirection.Input);
par2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
par2.Value = new int { 3, 4};
par2.Size = 2:
edited Nov 7 at 8:53
answered Nov 7 at 8:09
Wernfried Domscheit
23.1k42757
23.1k42757
I tried to call this procedure using Java and it worked properly. Even though it uses varray. If you mean I cannot user varray in C#, then this makes more sense. If you could post some code of a call to a stored procedure which takes an associative array of UDT as a parameter I would be very thankful.
– Ali A. Ismaeel
Nov 7 at 8:20
You can pass one value of a UDT or a list of simple data types (e.g NUMBER, VARCHAR2, etc.) which have to be declared as Associative Array in PL/SQL. But you cannot pass a list of UDT values.
– Wernfried Domscheit
Nov 7 at 8:46
I have successfully passed a varray of UDT using Java. So I suppose the restriction on passing a varray of UDT does not come from the database itself, but from ODP. However, there is an OracleDbType called Array. It must have some use. I have read the relevant documentation from Oracle and I did not find anything that implies that I cannot pass a varray of UDT.
– Ali A. Ismaeel
Nov 7 at 9:40
I found this OracleDbType Enumeration Type.OracleDbType.Array
was not available in earlier releases, looks like Oracle added this type. So, my statement "You can use only Associative Array" seems to be wrong meanwhile. However, I assume it is still valid to say "You can pass one value of a UDT or a list of simple data types"
– Wernfried Domscheit
Nov 7 at 10:09
add a comment |
I tried to call this procedure using Java and it worked properly. Even though it uses varray. If you mean I cannot user varray in C#, then this makes more sense. If you could post some code of a call to a stored procedure which takes an associative array of UDT as a parameter I would be very thankful.
– Ali A. Ismaeel
Nov 7 at 8:20
You can pass one value of a UDT or a list of simple data types (e.g NUMBER, VARCHAR2, etc.) which have to be declared as Associative Array in PL/SQL. But you cannot pass a list of UDT values.
– Wernfried Domscheit
Nov 7 at 8:46
I have successfully passed a varray of UDT using Java. So I suppose the restriction on passing a varray of UDT does not come from the database itself, but from ODP. However, there is an OracleDbType called Array. It must have some use. I have read the relevant documentation from Oracle and I did not find anything that implies that I cannot pass a varray of UDT.
– Ali A. Ismaeel
Nov 7 at 9:40
I found this OracleDbType Enumeration Type.OracleDbType.Array
was not available in earlier releases, looks like Oracle added this type. So, my statement "You can use only Associative Array" seems to be wrong meanwhile. However, I assume it is still valid to say "You can pass one value of a UDT or a list of simple data types"
– Wernfried Domscheit
Nov 7 at 10:09
I tried to call this procedure using Java and it worked properly. Even though it uses varray. If you mean I cannot user varray in C#, then this makes more sense. If you could post some code of a call to a stored procedure which takes an associative array of UDT as a parameter I would be very thankful.
– Ali A. Ismaeel
Nov 7 at 8:20
I tried to call this procedure using Java and it worked properly. Even though it uses varray. If you mean I cannot user varray in C#, then this makes more sense. If you could post some code of a call to a stored procedure which takes an associative array of UDT as a parameter I would be very thankful.
– Ali A. Ismaeel
Nov 7 at 8:20
You can pass one value of a UDT or a list of simple data types (e.g NUMBER, VARCHAR2, etc.) which have to be declared as Associative Array in PL/SQL. But you cannot pass a list of UDT values.
– Wernfried Domscheit
Nov 7 at 8:46
You can pass one value of a UDT or a list of simple data types (e.g NUMBER, VARCHAR2, etc.) which have to be declared as Associative Array in PL/SQL. But you cannot pass a list of UDT values.
– Wernfried Domscheit
Nov 7 at 8:46
I have successfully passed a varray of UDT using Java. So I suppose the restriction on passing a varray of UDT does not come from the database itself, but from ODP. However, there is an OracleDbType called Array. It must have some use. I have read the relevant documentation from Oracle and I did not find anything that implies that I cannot pass a varray of UDT.
– Ali A. Ismaeel
Nov 7 at 9:40
I have successfully passed a varray of UDT using Java. So I suppose the restriction on passing a varray of UDT does not come from the database itself, but from ODP. However, there is an OracleDbType called Array. It must have some use. I have read the relevant documentation from Oracle and I did not find anything that implies that I cannot pass a varray of UDT.
– Ali A. Ismaeel
Nov 7 at 9:40
I found this OracleDbType Enumeration Type.
OracleDbType.Array
was not available in earlier releases, looks like Oracle added this type. So, my statement "You can use only Associative Array" seems to be wrong meanwhile. However, I assume it is still valid to say "You can pass one value of a UDT or a list of simple data types"– Wernfried Domscheit
Nov 7 at 10:09
I found this OracleDbType Enumeration Type.
OracleDbType.Array
was not available in earlier releases, looks like Oracle added this type. So, my statement "You can use only Associative Array" seems to be wrong meanwhile. However, I assume it is still valid to say "You can pass one value of a UDT or a list of simple data types"– Wernfried Domscheit
Nov 7 at 10:09
add a comment |
Ali A. Ismaeel is a new contributor. Be nice, and check out our Code of Conduct.
Ali A. Ismaeel is a new contributor. Be nice, and check out our Code of Conduct.
Ali A. Ismaeel is a new contributor. Be nice, and check out our Code of Conduct.
Ali A. Ismaeel is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185101%2fnullreferenceexception-thrown-from-oracle-dataaccess-dll%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Which line of your code is it failing on? I understand the exception is within the Oracle assembly, but it would be useful to know whether it's reached
ExecuteNonQuery
or not.– Jon Skeet
Nov 7 at 7:33
The Exception is thrown from within the ExecuteNonQuery.
– Ali A. Ismaeel
Nov 7 at 7:35
1
Please add the stack trace into the post. Also, if you could add whether you have any other calls working with UDTs, that would be useful. (Does this UDT work elsewhere? Do you have different UDTs that work?)
– Jon Skeet
Nov 7 at 7:39
I have no other working calls with the same udt
– Ali A. Ismaeel
Nov 7 at 7:47
Do you have this working with other UDTs though? If it's this UDT that is causing problems, have you experimented with using it in simpler scenarios (e.g. without arrays)? What's in the UDT, and have you tried diagnosing this by making the UDT simpler and simpler?
– Jon Skeet
Nov 7 at 8:01