Skip to content

Commit b07a524

Browse files
Show how to correctly bind data to insert into NVARCHAR2 columns.
1 parent 1d1e171 commit b07a524

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

doc/src/api_manual/module.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ version of python-oracledb.
23872387

23882388
.. data:: NCHAR
23892389

2390-
A synonym for :data:`DB_TYPE_NVARCHAR`.
2390+
A synonym for :data:`DB_TYPE_NCHAR`.
23912391

23922392
.. deprecated:: cx_Oracle 8.0
23932393

doc/src/user_guide/globalization.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,22 @@ To convert dates:
215215
for row in cursor:
216216
print(row) # gives 'Mi 15 Dez 19:57:56 2021'
217217
print()
218+
219+
Inserting NVARCHAR2 and NCHAR Data
220+
----------------------------------
221+
222+
To bind NVARCHAR2 data, use :func:`Cursor.setinputsizes()` or create a bind
223+
variable with the correct type by calling :func:`Cursor.var()`. This removes
224+
an internal character set conversion to the standard `Database Character Set`_
225+
that may corrupt data. By binding as :data:`oracledb.DB_TYPE_NVARCHAR`, the
226+
data is inserted directly as the `Database National Character Set`_. For
227+
example, to insert into a table containing two NVARCHAR2 columns:
228+
229+
.. code-block:: python
230+
231+
sql = "insert into mytable values (:1, :2)"
232+
bv = ['data1', 'data2']
233+
cursor.setinputsizes(oracledb.DB_TYPE_NVARCHAR, oracledb.DB_TYPE_NVARCHAR)
234+
cursor.execute(sql, bv)
235+
236+
For NCHAR data, bind as :data:`oracledb.DB_TYPE_NCHAR`.

0 commit comments

Comments
 (0)