简体   繁体   English

用 Python 希腊字母写入 (Oracle) SQL 文件不起作用

[英]Writing with Python Greek letters to (Oracle) SQL file doesn't work

I'm trying to write Greek letters to file with ".sql" extension.我正在尝试将希腊字母写入带有“.sql”扩展名的文件。 But the result in the file are not correct.但是文件中的结果不正确。

The code in Python: Python中的代码:

with open('test.sql', 'w', encoding='utf-8') as test_file:
    test_file.write('DH5α\n')

In the SQL file I get:在 SQL 文件中,我得到:

DH5α

Any way I can solve this?我有什么办法可以解决这个问题?

OS is windows操作系统是windows

Thanks.谢谢。

From the cx_Oracle documentation Character Sets and Globalization make sure your connections are opened with the right character set.从 cx_Oracle 文档Character Sets and Globalization确保您的连接使用正确的字符集打开。

import cx_Oracle
connection = cx_Oracle.connect(connectString, encoding="US-ASCII", nencoding="UTF-8")

Note that with cx_Oracle 8, the defaults changed to be "UTF-8".请注意,在 cx_Oracle 8 中,默认值更改为“UTF-8”。

正如评论中所写,问题出在 sql-developer 本身,它默认不使用 utf-8 编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM