zoukankan      html  css  js  c++  java
  • C# Retrieving Associative Arrays from PL/SQL Code

    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_GetAllProductNames(ProdNames OUT StringArray);
    END ProductsPackage;
     /
    CREATE OR REPLACE PACKAGE BODY ProductsPackage IS
      PROCEDURE proc_GetAllProductNames(ProdNames OUT StringArray)
     IS
     BEGIN
        SELECT Name BULK COLLECT INTO ProdNames FROM Products;
     END;
    END ProductsPackage;

    /

    private void btnGetAllProductNames(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_GetAllProductNames";
                    _cmdObj.CommandType = CommandType.StoredProcedure;
     
        //Create an output parameter
                    OracleParameter _NameParam = new OracleParameter();
                    _NameParam.ParameterName = "ProdNames";
                    _NameParam.OracleDbType = OracleDbType.Varchar2 ;
                    _NameParam.Direction = ParameterDirection.Output;
                    _NameParam.CollectionType = OracleCollectionType.PLSQLAssociativeArray; 
     //You must explicitly define the number of elements to return           
     _NameParam.Size = 10;
    //Because you are retrieving an object with a variable size, you need to
    //define the size of the string returned. This size must be specified for
    //each element in the output result
     int[] intArray= new int[10];
     int _counter;
     for (_counter = 0; _counter < 10; _counter++) {intArray[_counter] = 255;}
     _NameParam.ArrayBindSize = intArray;
    //Execute the stored procedure
     _cmdObj.Parameters.Add(_NameParam);
     _cmdObj.ExecuteNonQuery();
    //For VARCHAR2 data types, an array of OracleString objects is returned
     String _result="";
     OracleString[] stringArray = (OracleString[])_NameParam.Value;
     for (_counter = 0; _counter <= stringArray.GetUpperBound(0); _counter++)
     {
         OracleString _outputString = stringArray[_counter];
         _result = _result + _outputString.Value + "\n";
     }
     MessageBox.Show("Product names are:\n" + _result);
     
     _connObj.Close();
     _connObj.Dispose();
     _connObj = null; }
      catch (Exception ex)
     {
      MessageBox.Show(ex.ToString());
     }
    }

  • 相关阅读:
    js修改input的type属性问题(兼容所有浏览器,主要用于密码类的默认有提示文字的效果)
    让一个div始终固定在页面的某一固定位置的方法
    js在IE8+兼容String没有trim方法,写一个兼容ie8一下的浏览器的trim()方法
    js用new Object创建json数据
    js+php实现文件上传显示文件上传进度条的插件
    关于一个页面的tab切换整体页面刷新而tab标签处是同一个文件怎么做焦点的问题
    B树及2-3树的python实现
    二叉查找树转变为有序双向链表
    Django中的静态文件管理
    Django文档——Model中的ForeignKey,ManyToManyField与OneToOneField
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1795116.html
Copyright © 2011-2022 走看看