Skip to content

Commit 9db9d69

Browse files
Batch loading documentation improvements.
1 parent 00dc44e commit 9db9d69

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

doc/src/user_guide/batch_statement.rst

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ processing will be sufficient.
238238
Loading CSV Files into Oracle Database
239239
======================================
240240

241-
The :meth:`Cursor.executemany()` method and `csv module
241+
The :meth:`Cursor.executemany()` method and Python's `csv module
242242
<https://docs.python.org/3/library/csv.html#module-csv>`__ can be used to
243243
efficiently load CSV (Comma Separated Values) files. For example, consider the
244244
file ``data.csv``::
@@ -255,21 +255,24 @@ And the schema:
255255
256256
create table test (id number, name varchar2(25));
257257
258-
Instead of looping through each line of the CSV file and inserting it
259-
individually, you can insert batches of records using
260-
:meth:`Cursor.executemany()`:
258+
Data loading can be done in batches of records since the number of records may
259+
prevent all data being inserted at once:
261260

262261
.. code-block:: python
263262
264263
import cx_Oracle
265264
import csv
266265
267-
. . .
268-
269-
# Predefine the memory areas to match the table definition
266+
# Predefine the memory areas to match the table definition.
267+
# This can improve performance by avoiding memory reallocations.
268+
# Here, one parameter is passed for each of the columns.
269+
# "None" is used for the ID column, since the size of NUMBER isn't
270+
# variable. The "25" matches the maximum expected data size for the
271+
# NAME column
270272
cursor.setinputsizes(None, 25)
271273
272-
# Adjust the batch size to meet your memory and performance requirements
274+
# Adjust the number of rows to be inserted in each iteration
275+
# to meet your memory and performance requirements
273276
batch_size = 10000
274277
275278
with open('testsp.csv', 'r') as csv_file:
@@ -284,3 +287,8 @@ individually, you can insert batches of records using
284287
if data:
285288
cursor.executemany(sql, data)
286289
con.commit()
290+
291+
292+
Depending on data sizes and business requirements, database changes such as
293+
temporarily disabling redo logging on the table, or disabling indexes may also
294+
be beneficial.

0 commit comments

Comments
 (0)