Oracle clob over dblink 使用不同的字符集

发布于 2024-09-12 20:49:41 字数 613 浏览 5 评论 0原文

场景如下:

Oracle A:字符集 WE8ISO8859P1

Oracle B:字符集 WE8MSWIN1252

Oracle A <- dblink -> Oracle B

我无法直接访问 Oracle B,防火墙问题:(

我必须从 OracleB 获取一些二进制文件,这些文件位于 CLOB 类型的列中(不要问我为什么不能更改为 BLOB)。

我使用“选择插入”将文件从 B 获取到 A,然后使用找到的 clob_to_blob 函数将它们转换为二进制文件。 dbforums.com/oracle/1624851-clob-blob.html#post6313513" rel="nofollow noreferrer">此处。

我收到一些损坏的文件,我相信这是因为 Oracle 通过以下方式自动将 WE8MSWIN1252 转换为 WE8ISO8859P1 dblink (嗯,该列是 CLOB,所以它是文本,对吧?)。

无法以任何方式更改数据库字符集,

有什么解决方法吗?

Here is the scenario:

Oracle A: charset WE8ISO8859P1

Oracle B: charset WE8MSWIN1252

Oracle A <- dblink -> Oracle B

I can't access Oracle B directly, firewall issues :(

I have to get some binary files from OracleB and these files are in a column of type CLOB (don't ask me why and I can't change to BLOB).

I'm using a "select insert" to get the files from B to A and them converting them to binary using clob_to_blob function found here.

I'm getting some corrupted files and I believe it's because Oracle is converting WE8MSWIN1252 to WE8ISO8859P1 automatically over the dblink (well, the column is CLOB so it's text, right?).

I can't change the databases charsets in any way.

Is there any workaround for this?

Thanks in advance

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

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

发布评论

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

评论(3

带上头具痛哭 2024-09-19 20:49:41

您是否尝试过使用 DBMS_LOB.CONVERTTOBLOB@remote(....)

但您可能想要获取远程 CLOB 的某种校验和,以查看它们在从任何原始外部源插入/更新时是否进行字符集转换。也就是说,如果插入完成时客户端字符集与数据库字符集不同,则在执行选择之前问题可能已经发生。


编辑添加。

我能想到的最接近的方法需要链接另一端的一些对象。
首先是在远程端进行转换的函数。
其次是呈现数据“BLOB”视图的视图。
这使用了一个虚拟表(基于 v$sql,因为它是我能找到的第一个 CLOB)。我没有理由认为您不能简单地将 CLOB 作为参数传递给函数。

create or replace function ret_blob return blob is
  cursor c_1 is 
  select sql_fulltext, sql_id, length(sql_fulltext) 
  from v_sql
  where sql_id = 'bzmb01whp36wt';
  rec_c1 c_1%rowtype;
  --
  v_blob  blob;
  v_dest  number := 1;
  v_src   number := 1;
  v_lang  number := 0;
  v_warn  number;
  --
begin
  open c_1;
  fetch c_1 into rec_c1;
  close c_1;
  dbms_lob.createtemporary(v_blob, TRUE);
  --
  dbms_lob.CONVERTTOBLOB (v_blob, rec_c1.sql_fulltext, DBMS_LOB.LOBMAXSIZE, 
        v_dest, v_src, DBMS_LOB.DEFAULT_CSID, v_lang, v_warn);
  --
  dbms_output.put_line(':'||v_warn||'>'||length(v_blob));
  --
  return v_blob;
end;
/

create view rblob as select ret_blob from dual;

然后,从本地数据库中执行

create table t as select ret_blob from rblob@remote

Have you tried to use DBMS_LOB.CONVERTTOBLOB@remote(....)

But you probably want to get some sort of checksum of the remote CLOB to see whether they are getting a characterset conversion when they are inserted/updated from whatever original external source. That is, if the client characterset, when the insert is done, is different from the database characterset, the problem may have already occurred before you do your select.


Edited to add.

The closest I can come up with requires some objects on the other end of the link.
Firstly a function that does the conversion at the remote end.
Secondly a view that presents a 'BLOB' view of the data.
This uses a dummy table (based of v$sql as it was the first CLOB I could find). No reason I can see that you can't simply pass the CLOB as a parameter to the function.

create or replace function ret_blob return blob is
  cursor c_1 is 
  select sql_fulltext, sql_id, length(sql_fulltext) 
  from v_sql
  where sql_id = 'bzmb01whp36wt';
  rec_c1 c_1%rowtype;
  --
  v_blob  blob;
  v_dest  number := 1;
  v_src   number := 1;
  v_lang  number := 0;
  v_warn  number;
  --
begin
  open c_1;
  fetch c_1 into rec_c1;
  close c_1;
  dbms_lob.createtemporary(v_blob, TRUE);
  --
  dbms_lob.CONVERTTOBLOB (v_blob, rec_c1.sql_fulltext, DBMS_LOB.LOBMAXSIZE, 
        v_dest, v_src, DBMS_LOB.DEFAULT_CSID, v_lang, v_warn);
  --
  dbms_output.put_line(':'||v_warn||'>'||length(v_blob));
  --
  return v_blob;
end;
/

create view rblob as select ret_blob from dual;

Then, from the local database, do a

create table t as select ret_blob from rblob@remote
木落 2024-09-19 20:49:41

我最好的建议是不要使用数据库链接,而是这样做:

  1. 获取一个客户端程序,无论是独立的还是您自己的,从 Oracle B 中提取 CLOB 并将数据写出作为包含正确二进制文件的“文本”文件数据。
  2. 将该文件作为二进制文件导入到 Oracle A 中的 BLOB 中。

My best suggestion would be not to use the DB link but instead do this:

  1. Get a client program, either standalone or your own, to extract the CLOB from Oracle B and write the data out as a "text" file which contains the correct binary data.
  2. Import that file into Oracle A as a binary file into the BLOB.
征棹 2024-09-19 20:49:41

一个完全不同的选择。
创建与B具有相同字符集的数据库C。将数据从B拉到C(不进行任何转换),然后您可以在将数据移动到A之前在C中进行操作。

A totally different alternative.
Create database C with the same characterset as B. Pull the data from B to C (without any conversion), then you can do you manipulation in C before moving the data to A.

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