0

I've been trying to call a procedure that takes in 3 different arrays as parameters but although I've tried a lot of different ways to do this I keep getting the exception saying that the amount or type of parameters is incorrect somewhere. Can you guys help me figuring what exactly am I doing wrong?

This is my code so far:

 using (var command = new OracleCommand(sql, connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.BindByName = true;
                command.Connection.Open();

                //Bind Client Ids Array to Database Parameter
                var nArrClientId = new OracleParameter("nArrClientId", OracleDbType.Int32)
                {
                    Size = clientIds.Length,
                    ArrayBindSize = new int[clientIds.Length],                        
                    Direction = ParameterDirection.Input,
                    CollectionType = OracleCollectionType.PLSQLAssociativeArray
                };

                for (var index = 0; index < clientIds.Length; index++)
                {
                    nArrClientId.ArrayBindSize[index] = 12;                       
                }
                nArrClientId.Value = clientIds;

                //Bind DocNames Array to Database Parameter
                var vArrDocNum = new OracleParameter("vArrDocNum", OracleDbType.Varchar2)
                {
                    Size = docNums.Length,
                    ArrayBindSize = new int[docNums.Length],                        
                    Direction = ParameterDirection.Input,
                    CollectionType = OracleCollectionType.PLSQLAssociativeArray
                };
                for (var index = 0; index < docNums.Length; index++)
                {
                    vArrDocNum.ArrayBindSize[index] = 20;                        
                }
                vArrDocNum.Value = docNums;

                //Bind Status Array to Database Parameter
                var vArrStatus = new OracleParameter("vArrStatus", OracleDbType.Varchar2)
                {
                    Size = statusArr.Length,
                    ArrayBindSize = new int[statusArr.Length],                       
                    Direction = ParameterDirection.Input,
                    CollectionType = OracleCollectionType.PLSQLAssociativeArray
                };
                for (var index = 0; index < statusArr.Length; index++)
                {
                    vArrStatus.ArrayBindSize[index] = 15;                        
                }
                vArrStatus.Value = statusArr;

                command.Parameters.Add(nArrClientId);
                command.Parameters.Add(vArrDocNum);
                command.Parameters.Add(vArrStatus);                  

                command.ExecuteNonQuery();
                connection.Close();                  
                command.Connection.Close();
            }

This is the Procedure Definition on Oracle

   TYPE tnClientId IS TABLE OF clients.id%TYPE INDEX by pls_integer; -- Number (12,0)
TYPE tvDocNumber IS TABLE OF documents.document_number%TYPE INDEX by pls_integer; --VARCHAR2 (20 BYTES)

TYPE tvStatus IS TABLE OF varchar2(15);


PROCEDURE update_status (nArrClientId   IN tnClientId,
                     vArrDocNum     IN tvDocNumber,
                     vArrStatus     IN tvStatus);

Any help is more than welcomed

2
  • PL/SQL Table is not possible, you must use Associative Arrays, i.e. with INDEX BY ... Commented Jul 26, 2016 at 20:18
  • Not sure what that means :( Commented Jul 26, 2016 at 20:25

1 Answer 1

1

You cannot use Nested table, you must use Associative Arrays.

I.e. TYPE tvStatus IS TABLE OF varchar2(15); is not possible you must use

TYPE tvStatus IS TABLE OF varchar2(15) INDEX by pls_integer;

What is the type of clientIds, docNums and statusArr? They must be arrays, perhaps you have to write like vArrDocNum.Value = docNums.ToArray();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.