Oracle Unicode 假脱机

发布于 2024-08-11 16:28:22 字数 287 浏览 3 评论 0原文

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

我有一个从 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掩耳倾听 2024-08-18 16:28:22

通过正确的设置,您的脚本可以与 SQL*Plus 一起使用。这是我测试它的方法:(

  • 显然)你的数据库必须支持 unicode。如有必要,请使用 NVARCHAR2。
  • 设置您的客户端应用程序正确。确保您的 NLS_LANG 变量设置正确,它必须支持 unicode。我将其设置为 AMERICAN_ENGLISH.UTF8。虽然 SQL*Plus 的 DOS 窗口不会显示所有 unicode 字符,但它们将被正确地假脱机到文件中。
  • (显然也是如此)确保读取假脱机文件的应用程序以正确的字符集打开它。

现在是脚本:

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

这将插入俄语字符ЙЖ

SQL> SPOOL STREET_POINT_THR.BQSV
SQL> SELECT * FROM STREET_POINTS;
ðÖðû
SQL> SPOOL OFF

使用文本编辑器(在我的例子中是jEdit)使用正确的字符集(UTF-8)打开的文件会正确显示字符。

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.

你的背包 2024-08-18 16:28:22

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

马克·福特
底栖软件
www.benthicsoftware.com

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文