Oracle Unicode Spooling

社会主义新天地 提交于 2019-12-18 09:14:04

问题


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

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

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

回答1:


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

  • (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.

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;
ðÖðû
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.




回答2:


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.

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.



来源:https://stackoverflow.com/questions/1749337/oracle-unicode-spooling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!