来自 Oracle 表的 UTF 8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/355538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:33:34  来源:igfitidea点击:

UTF 8 from Oracle tables

oracle

提问by Robert

The client has asked for a number of tables to be extracted into csv's, all done no problem. They've just asked we make sure the files are always in UTF 8 format.

客户要求将许多表提取到 csv 中,都没有问题。他们刚刚要求我们确保文件始终采用 UTF 8 格式。

How do I check this is actually the case. Or even better force it to be so, is it something i can set in a procedure before running a query perhaps?

我如何检查是否确实如此。或者甚至更好地强制它如此,我是否可以在运行查询之前在程序中设置它?

The data is extracted from an Oracle 10g database.

数据是从 Oracle 10g 数据库中提取的。

What should I be checking?

我应该检查什么?

Thanks

谢谢

回答by rics

You can check the database character set with the following query:

您可以使用以下查询检查数据库字符集:

select value from nls_database_parameters 
where parameter='NLS_CHARACTERSET'

If it says AL32UTF8 then your database is in the format what you need and if the export does not impair it then your are done.

如果它说 AL32UTF8 那么你的数据库就是你需要的格式,如果导出没有损害它那么你就完成了。

You may read about Oracle globalization support here, and hereabout NLS parameters like the above.

您可以在此处阅读有关 Oracle 全球化支持的信息在此处阅读有关上述 NLS 参数的信息。

回答by Justin Cave

How, exactly, are you generating the CSV files? Depending on the exact architecture, there will be different answers.

您究竟是如何生成 CSV 文件的?根据确切的架构,会有不同的答案。

If you are, for example, using SQL*Plus to extract the data, you would need to set the NLS_LANGon the client machine to something appropriate (i.e. AMERICAN_AMERICA.AL32UTF8) to force the data to be sent to the client machine in UTF-8. If you are using other approaches, NLS_LANGmay or may not be important.

例如,如果您使用 SQL*Plus 提取数据,则需要NLS_LANG在客户端计算机上将 设置为适当的值(即 AMERICAN_AMERICA.AL32UTF8)以强制将数据以 UTF-8 格式发送到客户端计算机. 如果您使用其他方法,NLS_LANG可能重要也可能不重要。

回答by Robert

Ok it wasn't as simple as I first hoped. The query above returns AL32UTF8.

好吧,这并不像我最初希望的那么简单。上面的查询返回 AL32UTF8。

I am using a stored proc compiled on the database to loop through a list of table names held in an array inside the stored procedure.

我正在使用在数据库上编译的存储过程来循环遍历存储过程内数组中保存的表名列表。

I use DBMS_SQL package to build the SQL and UTL_FILE.PUT_NCHAR to insert data into a text file.

我使用 DBMS_SQL 包来构建 SQL 和 UTL_FILE.PUT_NCHAR 将数据插入到文本文件中。

I believed then my resultant output would be in UTF 8 however opening in Textpad says it's in ANSI and the data is garbled in places :)

我相信我的结果输出将是 UTF 8,但是在 Textpad 中打开说它是 ANSI 并且数据在某些地方是乱码:)

Cheers

干杯

It might be important that NLS_CHARACTERSET is AL32UTF8 and NLS_NCHAR_CHARACTERSET is AL16UTF16

NLS_CHARACTERSET 是 AL32UTF8 并且 NLS_NCHAR_CHARACTERSET 是 AL16UTF16 可能很重要

回答by James Anderson

What you have to look for is the eight-bit ascii characters in hte input (if any) are translated into double byte utf-8 characters.

您必须寻找的是 hte 输入中的八位 ascii 字符(如果有)被转换为双字节 utf-8 字符。

This is highly dependant on your local ASCII code page but typically:- ASCII "£" should be x'A3' in ascii magically becomes x'C2A3' in utf-8.

这高度依赖于您的本地 ASCII 代码页,但通常:- ASCII“£”应该是 ascii 中的 x'A3' 神奇地变成 utf-8 中的 x'C2A3'。