|
|
|
Sometimes you need to put large amount of data to Oracle database. Certainly you may construct INSERT SQL statement and execute it with OraCommand object. But it takes a lot of time. You can greatly speed up loading time of data by using DML array features. Oracle 8i has better way to do it. With Oracle 8i it is possible to use direct path load interface. The direct path load interface allows to access the direct path load engine of the Oracle database server to perform the functions of the Oracle SQL*Loader utility. This functionality provides the ability to load data from external files into Oracle database objects, either a table or a partition of a partitioned table.
OCL simplifies using direct path load interface by OraLoader class. OraLoader allows you to load various formatted data. The capability of OraLoader object to load various formatted data is reached by reading external data in itself writing method.
Suppose you have the following table:
CREATE TABLE OCL_LOADER (
ID NUMBER,
STR_T VARCHAR(20),
INT_T NUMBER(6),
DOUBLE_T NUMBER,
DATE_T DATE
)
To load data to this table you may write such code:
...
// Set up connection that will be used for loading
// and loading table name
OraLoader loader(connection, "ocl_loader");
// Auto-create columns for specified table
loader.createColumns();
// Prepare loader for loading
loader.beginLoad();
cout << "Loading...\n";
srand((unsigned)time(NULL));
// Put data to the loader internal buffer
for (int i = 0; i < 100000; i++) {
loader.putColumnData(0, i);
loader.putColumnData(1, "loader demo string");
loader.putColumnData(2, rand());
loader.putColumnData(3, (double)rand()/10);
loader.putColumnData(4, CRDate(2002, 04, 11));
// If loader buffer is full flush it to the table
loader.putNextRow();
}
// Flush existing data and clear internal loader structures
loader.finishLoad();
...
Note that almost all OraLoader methods may throw an exception, therefore you must use C++ exception handling mechanism.
See Also
OraLoader, LoaderColumn, loader demo project
OCL | Using OCL | Index