C # Passing Associative Arrays to PL/SQL Code

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.