Create or replace package ProductsPackage IS
TYPE DecimalArray is table of decimal index by BINARY_INTEGER;
TYPE StringArray is table of VARCHAR2 (255) index by BINARY_INTEGER;
PROCEDURE proc_UpdateMultiplePrices (ProdPrices IN DecimalArray, ProdNames IN
StringArray );
END ProductsPackage;
/
Create or replace package body ProductsPackage IS
PROCEDURE proc_UpdateMultiplePrices (ProdPrices IN DecimalArray, ProdNames IN
StringArray)
IS
BEGIN
FOR I IN 1 .. ProdNames. LAST
LOOP
UPDATE Products SET Price = Price + ProdPrices (I) WHERE Name =
ProdNames (I );
End loop;
END;
END ProductsPackage;
/
Private void btnUpdateMultiplePrices_Click (object sender, EventArgs e)
{
String _ connstring = "Data Source = localhost/NEWDB; User
Id = EDZEHOO; Password = PASS123 ;";
Try
{OracleConnection _ connObj = new OracleConnection (_ connstring );
_ ConnObj. Open ();
OracleCommand _ cmdObj = _ connObj. CreateCommand ();
_ CmdObj. CommandText = "ProductsPackage. proc_UpdateMultiplePrices ";
_ CmdObj. CommandType = CommandType. StoredProcedure;
OracleParameter _ priceParam = new OracleParameter ();
_ PriceParam. ParameterName = "ProdPrices ";
_ PriceParam. OracleDbType = OracleDbType. Decimal;
_ PriceParam. Direction = ParameterDirection. Input;
_ PriceParam. CollectionType = OracleCollectionType. PLSQLAssociativeArray;
Decimal [] decArray = new Decimal [3];
DecArray [0] = 100;
DecArray [1] = 300;
DecArray [2] = 500;
_ PriceParam. Value = decArray;
_ CmdObj. Parameters. Add (_ priceParam );
OracleParameter _ NameParam = new OracleParameter ();
_ NameParam. ParameterName = "ProdNames ";
_ NameParam. OracleDbType = OracleDbType. Varchar2;
_ NameParam. Direction = ParameterDirection. Input;
_ NameParam. CollectionType = OracleCollectionType. PLSQLAssociativeArray;
String [] stringArray = new String [3];
StringArray [0] = "Engine ";
StringArray [1] = "Windshield ";
Stringarray [2] = "rear lights ";
_ Nameparam. value = stringarray;
_ Cmdobj. Parameters. Add (_ nameparam );
_ Cmdobj. executenonquery (); MessageBox. Show ("all products updated! ");
_ Connobj. Close ();
_ Connobj. Dispose ();
_ Connobj = NULL;
}
Catch (exception ex)
{
MessageBox. Show (ex. tostring ());
}
}