ODAC application Techniques (iv) using VARRAY data types

Source: Internet
Author: User

It is recommended that you use an array when working with objects. But there may be problems when you need to use a large array in a dataset. For example, when a large array of ODAC is created for a field, a large number of Tfield fields are also created, which can cause the program's performance to be greatly reduced. Therefore, the ODAC limit can only create 1000 members for a field. But either way, you can use the Toraarray object to access all the members. Of course, you can do it in other ways. For example, set Toraquery.sparsearray to True and access array members by Tarrayfield objects.

If the following types are created:

CREATE TYPE TODACArray1 AS VARRAY (5) OF NUMBER;

CREATE TYPE TODACArray2 AS VARRAY (4) OF CHAR(10);

CREATE TABLE ODAC_Array (
Code NUMBER,
Title VARCHAR2(10),
Arr1 TODACArray1,
Arr2 TODACArray2,
);

To access an array member, you need to invoke the method Fieldbyname. For example:

Value := Query.FieldByName(''''Arr1[0]'''').AsInteger;

If ObjectField property is True this code is right

Value := TArrayField(Query.FieldByName(''''Arr1'''')).Fields[0].AsInteger;

Using TOraDataSet.GetArray you can access to array items through TOraArray object

Value:= Query.GetArray(''''Arr1'''').ItemAsInteger[0];

You can use the Varray type as a parameter in SQL and PL/SQL statements. You need to specify Dtarray to Toraparam.datatype and use the Toraparam.asarray property to access the array members.

For example:

var
OraSQL: TOraSQL;
. . .
OraSQL.SQL.Text := ''''INSERT INTO ODAC_Array (Code, Arr1, Arr2)''''
''''VALUES (:Code, :Arr1, :Arr2)'''';

OraSQL.ParamByName(''''Code'''').AsInteger := 10;

with OraSQL.ParamByName(''''Arr1'''').AsArray do begin
AllocObject(OraSession.OCISvcCtx, ''''TODACArray1'''');
ItemAsInteger[0] := 12;
AttrAsInteger[''''[1]''''] := 10;
ItemAsInteger[3] := 133;
end;

with OraSQL. ParamByName(''''Arr2'''').AsArray do begin
OCISvcCtx:= OraSession.OCISvcCtx;
AllocObject(''''TODACArray2'''');
AttrAsString[''''[2]'''']:= ''''eeee'''';
ItemAsString[0]:= ''''FFFFF'''';
end;

OraSQL.Execute;

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.