Oracle Unicode 假脱机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1749337/
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 19:26:43  来源:igfitidea点击:

Oracle Unicode Spooling

oracleunicodespool

提问by Kaveh Shahbazian

How can I spool data from a table to a file which contains Unicode characters?

如何将表中的数据假脱机到包含 Unicode 字符的文件?

I have a sql file which I execute from SQL*Plus screen and its content is:

我有一个从 SQL*Plus 屏幕执行的 sql 文件,其内容是:

SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET PAGESIZE 0
SPOOL STREET_POINT_THR.BQSV
SELECT GEOX||'`'||GEOY||'`'||UNICODE_DESC||'`'||ASCII_DESC 
FROM GEO.STREET_POINTS;
SPOOL OFF

采纳答案by Vincent Malgrat

with the right settings your script does work with SQL*Plus. Here is what I did to test it:

使用正确的设置,您的脚本可以与 SQL*Plus 一起使用。这是我为测试它所做的:

  • (obviously) your database must support unicode. Use NVARCHAR2 if necessary.
  • Setup your client application correctly. make sure your NLS_LANG variable is set correctly, it must support unicode. I set mine to AMERICAN_ENGLISH.UTF8. While the DOS window of SQL*Plus won't display all unicode characters, they will be spooled correctly into the file.
  • (obviously too) make sure the application that reads the spooled file opens it in the right character set.
  • (显然)您的数据库必须支持 unicode。如有必要,请使用 NVARCHAR2。
  • 正确设置您的客户端应用程序。确保您的 NLS_LANG 变量设置正确,它必须支持 unicode。我将我的设置为AMERICAN_ENGLISH.UTF8. 虽然 SQL*Plus 的 DOS 窗口不会显示所有 unicode 字符,但它们会被正确地假脱机到文件中。
  • (显然也是如此)确保读取假脱机文件的应用程序以正确的字符集打开它。

Now for the script:

现在为脚本:

SQL> select * from v$nls_parameters where parameter = 'NLS_CHARACTERSET';

PARAMETER          VALUE
------------------ ------
NLS_CHARACTERSET   UTF8

SQL> create table street_points (data varchar2(10));

Table created

SQL> INSERT INTO street_points VALUES (chr(53401)||chr(53398));

1 row inserted

This will insert the russian characters ЙЖ

这将插入俄文字符 ЙЖ

SQL> SPOOL STREET_POINT_THR.BQSV
SQL> SELECT * FROM STREET_POINTS;
e?e?
SQL> SPOOL OFF

The file, opened with a text editor (jEdit in my case) with the correct character set (UTF-8) displays the characters correctly.

使用具有正确字符集 (UTF-8) 的文本编辑器(在我的情况下为 jEdit)打开的文件可以正确显示字符。

回答by MarkF

I don't think SQLPlus (at least on Windows) supports unicode. I just tested here and it doesn't seem to work. I'm not sure if it's ok to mention this here, but my own tool "Golden 6" does support unicode spooling although it is Windows only. Note that you have to use "SET ENCODING [UNICODE | UTF-8 | ANSI] [NOBOM]" before the spool command to choose the correct encoding.

我认为 SQLPlus(至少在 Windows 上)不支持 unicode。我刚刚在这里测试,它似乎不起作用。我不确定是否可以在这里提及这一点,但我自己的工具“Golden 6”确实支持 unicode 假脱机,尽管它仅适用于 Windows。请注意,您必须在 spool 命令之前使用“SET ENCODING [UNICODE | UTF-8 | ANSI] [NOBOM]”来选择正确的编码。

Mark Ford
Benthic Software
www.benthicsoftware.com

Mark Ford
Benthic Software
www.benthicsoftware.com

Edit: As Vincent pointed out, it is working. Note that the UTF-8 file created has no BOM but is a UTF-8 file.

编辑:正如文森特指出的那样,它正在起作用。请注意,创建的 UTF-8 文件没有 BOM,而是一个 UTF-8 文件。