@@ -21,9 +21,9 @@ other features that will be useful in applications. See the
2121Setting the Client Character Set
2222================================
2323
24- You can specify the Oracle client character set used by cx_Oracle by passing the
25- ``encoding `` and ``nencoding `` parameters to the :meth: `cx_Oracle.connect ` and
26- :meth: `cx_Oracle.SessionPool ` methods. For example:
24+ You can specify the Oracle client character set used by cx_Oracle by passing
25+ the ``encoding `` and ``nencoding `` parameters to the :meth: `cx_Oracle.connect `
26+ and :meth: `cx_Oracle.SessionPool ` methods. For example:
2727
2828.. code-block :: python
2929
@@ -34,35 +34,48 @@ You can specify the Oracle client character set used by cx_Oracle by passing the
3434 The ``encoding `` parameter affects character data such as VARCHAR2 and CLOB
3535columns. The ``nencoding `` parameter affects "National Character" data such as
3636NVARCHAR2 and NCLOB. If you are not using national character types, then you
37- can omit ``nencoding ``.
37+ can omit ``nencoding ``. Both the ``encoding `` and ``nencoding `` parameters are
38+ expected to be one of the `Python standard encodings
39+ <https://docs.python.org/3/library/codecs.html#standard-encodings> `__ such as
40+ ``UTF-8 ``. Do not accidentally use ``UTF8 ``, which Oracle uses to specify the
41+ older Unicode 3.0 Universal character set, ``CESU-8 ``. Note that Oracle does
42+ not recognize all of the encodings that Python recognizes. You can see which
43+ encodings Oracle supports by issuing this query:
3844
39- cx_Oracle will first treat the encoding parameter values as ` IANA encoding names
40- <https://www.iana.org/assignments/character-sets/character-sets.xhtml> `__. If
41- no name is matched, it will attempt to use ` Oracle character set names
42- <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-9529D1B5-7366-4195-94B5-0F90F3B472E1> `__. For
43- example, for `` UTF-8 `` characters you should use the IANA name "UTF-8" or the
44- Oracle name "AL32UTF8". Do not accidentally use "UTF8", which Oracle uses to
45- specify the older Unicode 3.0 Universal character set, `` CESU-8 ``.
45+ .. code-block :: sql
46+
47+ select distinct utl_i18n.map_charset(value)
48+ from v$nls_valid_values
49+ where parameter = 'CHARACTERSET'
50+ and utl_i18n.map_charset(value) is not null
51+ order by 1
4652
4753 An alternative to setting the encoding parameters is to set Oracle's
4854``NLS_LANG `` environment variable to a value such as
4955``AMERICAN_AMERICA.AL32UTF8 ``. See :ref: `Setting environment variables
5056<envset>`. As well as setting the character set, the ``NLS_LANG `` environment
5157variable lets you specify the Language (``AMERICAN `` in this example) and
52- Territory (``AMERICA ``) used for NLS globalization. See `Choosing a Locale with
53- the NLS_LANG Environment Variable
54- <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-86A29834-AE29-4BA5-8A78-E19C168B690A> `__.
58+ Territory (``AMERICA ``) used for NLS globalization. See
59+ `Choosing a Locale with the NLS_LANG Environment Variables
60+ <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&
61+ id=GUID-86A29834-AE29-4BA5-8A78-E19C168B690A> `__.
5562
5663A character set specified by an ``encoding `` parameter will override the
5764character set in ``NLS_LANG ``. The language and territory components will still
5865be used by Oracle.
5966
6067If the ``NLS_LANG `` environment variable is set in the application with
61- ``os.environ['NLS_LANG'] ``, it must be set before any connection pool is created,
62- or before any standalone connections are created.
68+ ``os.environ['NLS_LANG'] ``, it must be set before any connection pool is
69+ created, or before any standalone connections are created.
70+
71+ If neither of the encoding parameters are specified and the ``NLS_LANG ``
72+ environment variable is not set, the character set ``ASCII `` is used.
73+
74+ Other Oracle globalization variable can also be set, see
75+ `Setting NLS Parameters
76+ <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&
77+ id=GUID-6475CA50-6476-4559-AD87-35D431276B20> `__.
6378
64- Other Oracle globalization variable can also be set, see `Setting NLS Parameters
65- <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-6475CA50-6476-4559-AD87-35D431276B20> `__.
6679
6780Character Set Example
6881=====================
0 commit comments