dotConnect for Oracle Documentation
In This Topic
    VARRAY Type
    In This Topic

    dotConnect for Oracle provides two ways of working with Arrays and Nested tables:

    If such types are created:

    CREATE TYPE TArray1 AS VARRAY (5) OF NUMBER;
    
    CREATE TYPE TArray2 AS VARRAY (4) OF CHAR(10);
    
    CREATE TABLE ArrayTable (
      Code NUMBER,
      Title VARCHAR2(10),
      Arr1 TArray1,
      Arr2 TArray2
    );
    

    Filled dataset for the query

    SELECT * FROM ArrayTable
    

    will have three tables at dataset: ArrayTable, ArrayTableArr1, ArrayTableArr2. Using this way has a restriction that you are unable to post updated data to the server by DataAdapter.Update method.

    The another way to access data from Arrays and Nested tables is to use OracleArray and OracleTable classes. For example, for OracleArray type you can write the next code:

    OracleArray oraArray = dataReader.GetOracleArray(i);
    foreach (object obj in oraArray) {
      lbResult.Items.Add(obj.ToString());
    }
    
    
    dim oraArray as OracleArray = dataReader.GetOracleArray(i);
    dim obj as object
    for each obj in oraArray
      lbResult.Items.Add(obj.ToString())
    next
    
    

    You can use VARRAY type for parameters of SQL and PL/SQL statements.

    For example:

    OracleCommand cmd = oracleConnection1.CreateCommand();
    cmd.CommandText = "INSERT INTO ArrayTable (CODE, ARR1) VALUES (1, :ARR1)";
    cmd.Parameters.Add(new OracleParameter("ARR1", OracleDbType.Array));
    
    OracleArray arr1 = new OracleArray("SCOTT.TARRAY1", oracleConnection1);
    arr1.Add(10);
    arr1.Add(20);
    arr1.Add(30);
    
    cmd.Parameters["ARR1"].Value = arr1;
    cmd.ExecuteNonQuery();
    
    
    dim cmd as OracleCommand = OracleConnection1.CreateCommand()
    cmd.CommandText = "INSERT INTO ArrayTable (CODE, ARR1) VALUES (1, :ARR1)"
    cmd.Parameters.Add(New OracleParameter("ARR1", OracleDbType.Array))
    
    dim arr1 as OracleArray = new OracleArray("SCOTT.TARRAY1", OracleConnection1)
    arr1.Add(10)
    arr1.Add(20)
    arr1.Add(30)
    
    cmd.Parameters("ARR1").Value = arr1
    cmd.ExecuteNonQuery()
    
    

    See Also

    OracleArray Class  | Devart.Data.Oracle Namespace