简体   繁体   中英

Issue Binding Oracle Array Parameters in C#

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

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

Ie 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM