Skip to content

Can't insert into NVARCHAR2 datatype #119

@rbrodewicz

Description

@rbrodewicz

Can't insert into nvarchar2 data. Was trying to play with NLS_LANG, and python encoding/nencoding for connect object. Nothing works.
Querying data works.
Test case below (fetch value from DB, insert save value into DB).

DB

create table rbx (n nvarchar2(100));
insert into rbx (n) values(utl_raw.cast_to_nvarchar2('0105017C015B017A01070144014200F30119'));
commit;

select n, utl_raw.cast_to_raw(n) r from rbx;

N          R
---------- ----------------------------------------
ążśźćńłóę  0105017C015B017A01070144014200F30119

select * from nls_database_parameters
where parameter in ('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET');

PARAMETER                      VALUE
------------------------------ ------------------------------
NLS_CHARACTERSET               WE8ISO8859P1
NLS_NCHAR_CHARACTERSET         AL16UTF16

Python

import cx_Oracle

f8  = open('out8', 'w', encoding="utf-8")
f16 = open('out16','w', encoding="utf-16")

con = cx_Oracle.connect("user", "pass", "db", encoding='UTF-8', nencoding='UTF-16')
cur = con.cursor()

n = cur.execute("select n from rbx").fetchone()[0]

f8.write(n)
f16.write(n)

cur.prepare('insert into rbx (n) values (:n)')
cur.execute(None, {'n':n})

con.commit()

cur.close()
con.close()

DB

select n, utl_raw.cast_to_raw(n) r from rbx;

N          R
---------- ----------------------------------------
ążśźćńłóę  0105017C015B017A01070144014200F30119
¿¿¿¿¿¿¿ó¿  00BF00BF00BF00BF00BF00BF00BF00F300BF
  1. What is your version of Python? Is it 32-bit or 64-bit?
    64

  2. What is your version of cx_Oracle?
    6.0.2

  3. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
    11.2.0.4 Oracle client installation

  4. What is your version of the Oracle Database?
    11.2.0.4

  5. What is your OS and version?
    Windows 7 x64 / Red Hat 6.8

  6. What compiler version did you use? For example, with GCC, run
    gcc --version.
    4.4.7 (for Linux)

  7. What environment variables did you set? How exactly did you set them?
    None, NLS_LANG

  8. What error(s) you are seeing?
    No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions