informix 中对 blob 数据的操作

发布于 2024-10-08 12:46:45 字数 77 浏览 8 评论 0原文

我们如何对 blob 数据类型的某些文本使用子字符串、修剪、长度操作。我们如何使用查询更新 blob 数据类型的列?

谢谢,

How can we use substring, trim, length operations on some text of blob datatype. And how can we update a column of blob datatype using query?

Thanks,

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

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

发布评论

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

评论(3

云巢 2024-10-15 12:46:45

有困难!

首先,您正在讨论 4 种不同类型的 blob 中的哪一种:

  • BYTE
  • TEXT
  • BLOB
  • CLOB

这些是成对出现的(如西斯领主):有二进制版本(BYTE、BLOB)和文本版本(TEXT、CLOB)。还有另一种配对:旧的(BYTE、TEXT)和新的(BLOB、CLOB)。 BYTE 和 TEXT 类型是在 1989 年左右随 Informix OnLine 4.00 引入的。BLOB 和 CLOB 类型是在 1996 年随 Informix Universal Server 9.00 引入的,也称为 SmartBlob。

然而,有一个非常现实的意义,即您指的是哪种类型并不重要。

可以对 BYTE 和 TEXT blob 执行的操作非常少。它们可以被获取和存储,但出于所有实际目的,仅此而已。我相信您可以使用 LENGTH 来确定 TEXT blob 的长度。我不相信有任何方法可用于更新 BYTE 或 TEXT blob 的一部分;这是一个要么全有要么全无的替代品。此外,替换来自适当类型的主变量 - 没有 BYTE 或 TEXT 文字。

SmartBlobs 的情况要好一些,但我不是这方面的专家。有一些机制可以获取 LO(大对象)句柄,然后对其进行操作,但我认为这些机制在服务器端(从 SQL 或 SPL)不可用。我可能故意不了解 SmartBlob 的可用功能,但我认为这些操作只能通过编程 API 实现,而不能在 SQL 中实现。也没有 BLOB 或 CLOB 文字。但是,您可以使用 SQL 从文件(FILETOBLOB、FILETOCLOB)加载并写入文件(LOTOFILE) - 文件位于服务器或客户端上。

With difficulty!

First of all, which of the 4 various types of blob are you discussing:

  • BYTE
  • TEXT
  • BLOB
  • CLOB

These come in pairs (like Sith Lords): there is a binary version (BYTE, BLOB) and a text version (TEXT, CLOB). There's also another pairing: old (BYTE, TEXT) and newer (BLOB, CLOB). The BYTE and TEXT types were introduced with Informix OnLine 4.00 in about 1989. The BLOB and CLOB types were introduced with Informix Universal Server 9.00 in 1996, and are also known as SmartBlobs.

However, there's a very real sense in which it doesn't matter which of the types you are referring to.

There are very few operations that can be performed on BYTE and TEXT blobs. They can be fetched and stored, but for all practical purposes, that's all. I believe you can use LENGTH to determine the length of a TEXT blob. I don't believe there are any methods available to update part of BYTE or TEXT blob; it is an all-or-nothing replacement. Further, the replacement is from a host variable of the appropriate type - there are no BYTE or TEXT literals.

The situation is a bit better with SmartBlobs, but I'm not an expert on them. There are mechanisms for obtaining a LO (large object) handle and then manipulating that, but I don't think those are available server-side (from SQL or SPL). I may be willfully not understanding what's available with the SmartBlobs, but I think the operations are only available from programming APIs and not within SQL. There are no BLOB or CLOB literals either. However, you can use SQL to load from files (FILETOBLOB, FILETOCLOB) and write to files (LOTOFILE) - with the files either on the server or on the client.

ι不睡觉的鱼゛ 2024-10-15 12:46:45

我已经回答了您有关子字符串的问题:informix 中 blob 文本的子字符串操作
。对于 BLOB,您可以使用子字符串运算符,但不能使用 SUBSTRING() 或 SUBST() 函数。

您还可以使用LENGTH(),但不能使用TRIM()

示例代码:

CREATE TABLE _text_test (id serial, txt_vch varchar(200),  txt_text text);
INSERT INTO _text_test (txt_vch, txt_text) VALUES ('1234567890', '1234567890');
SELECT txt_vch, txt_text, txt_vch[3,5], txt_text[3,5], length(txt_text) FROM _text_test;

在我的示例中,我使用了 TEXT blob 类型(Jonathan 向您展示了更多 blob 类型,您应该向我们展示您所使用的 blob 类型)。最后的选择显示了子字符串运算符和 LENGTH() 函数的用法。您可以将 LENGTH() 函数替换为 TRIM() 等其他函数,以便在您的环境中对其进行测试。在我的例子中,TRIM() 测试结束于:

ODBC Error: -880 [Informix][Informix ODBC Driver][Informix]
Trim character and trim source must be of string data type.

最后一个选择与 JDBC 3.70JC1 驱动程序配合良好,但 ODBC 3.70TC1 驱动程序似乎有错误并显示 3 个第一个字符:123 而不是 345。自己测试一下。

I have already answered your question about substring: substring operation on blob text in informix
. With BLOBs you can use substring operator, but not SUBSTRING() nor SUBST() functions.

You can also use LENGTH(), but not TRIM().

Example code:

CREATE TABLE _text_test (id serial, txt_vch varchar(200),  txt_text text);
INSERT INTO _text_test (txt_vch, txt_text) VALUES ('1234567890', '1234567890');
SELECT txt_vch, txt_text, txt_vch[3,5], txt_text[3,5], length(txt_text) FROM _text_test;

In my example I used TEXT blob type (Jonathan showed you more blob types, you should show us what kind of blob you use in question). Last select shows usage of substring operator and LENGTH() function. You can replace LENGTH() function with other functions like TRIM() to test it with your environment. In my case TRIM() test ends with:

ODBC Error: -880 [Informix][Informix ODBC Driver][Informix]
Trim character and trim source must be of string data type.

Last select works well with JDBC 3.70JC1 driver, but it seems that ODBC 3.70TC1 driver has bug and shows 3 first chars: 123 instead of 345. Test it yourself.

情未る 2024-10-15 12:46:45

在最新版本(12.10)中,有 DBMS_LOB包
然而它并不像记录的那样工作:例如没有 dbms_lob.get_length 函数。相反,我发现 dbms_lob_get_length 正在按预期工作。
因此,对于 CLOB 字段,您有以下有用的操作:

  • dbms_lob_get_length;
  • dbms_lob_instr;
  • dbms_lob_substr(不幸的是它也在 get_length 之后获取数据);

我还发现了一个未记录但非常非常有用的函数:dbms_lob_new_clob,它获取 lvarchar 参数并将其转换为 CLOB。
我知道这个答案已经很晚了。我认为它对于其他人在 Informix 中搜索处理 blob 的方法很有用(几天前,当我开始关于使用 blob 存储 xml 的小型研究时,我发现了这篇文章)。

In recent version (12.10) there is DBMS_LOB package
However it doesn't work as documented: for example there is no dbms_lob.get_length function. Instead I've found that dbms_lob_get_length is working as expected.
So for CLOB fields you have following usefull operations:

  • dbms_lob_get_length;
  • dbms_lob_instr;
  • dbms_lob_substr (unfortunately it gets data after get_length too);

I've found also one undocumented but very, very useful function: dbms_lob_new_clob which gets lvarchar argument and it converts it to CLOB.
I know that this answer is very late. I think that it can be usefull for other people searching ways to handle blobs in Informix (I've found this post few days ago when I was starting mini-research about using blobs for storing xml).

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