cx_Oracle and UTF8

Diez B. Roggisch deets at nospam.web.de
Thu Feb 23 06:22:45 EST 2006


Harald Armin  Massa wrote:

> Hello,
> 
> I am looking for a method to convince cx_Oracle and oracle to encode
> it's replies in UTF8.
> 
> For the moment I have to...
> 
> cn=cx_Oracle.connect("user","password", "database")
> cs=cn.Cursor()
> 
> cs.execute("select column1, column2, column3 from table")
> 
> for row in cs.fetchall():
>    t=[]
>    for i in range(0,len(row)):
>       if hasattr(row[i],"encode"):
>         t.append(row[i].encode("utf8"))
>       else:
>         t.append(row[i])
>     print t
> 
> Guess I am to much accustomed to postgresql which just allows "set
> client_encoding='utf8'...

You can do that in Oracle, too. It's called NLS (national language support),
and it is like a locale-setting in python/C. I'm too lazy to google right
now, but you should be able to alter the current connection's session to
deliver strings in whatever encoding is supportde (utf-8 being amongst
these).

Diez



More information about the Python-list mailing list