Oracle 11g中如何存储无限字符?

发布于 2024-09-04 16:27:23 字数 505 浏览 8 评论 0原文

我们在 Oracle 11g 中有一个带有 varchar2 列的表。我们使用专有的编程语言,其中该列被定义为字符串。此列中最多可以存储 2000 个字符(4000 个字节)。现在的需求是该列需要存储超过2000个字符(实际上是无限个字符)。出于维护原因,DBA 不喜欢 BLOB 或 LONG 数据类型。

我能想到的解决方案是从原始表中删除这一列,并为该列建立一个单独的表,然后将每个字符存储在一行中,以获得无限的字符。该表将与原始表连接以进行查询。

对于这个问题有更好的解决办法吗?

更新:专有编程语言允许定义字符串和 blob 类型的变量,没有 CLOB 选项。我理解给出的答复,但我无法与 DBA 较量。我知道偏离 BLOB 或 LONG 将是开发人员的噩梦,但仍然无能为力。

更新 2:如果我需要的最大字符数是 8000 个字符,我可以再添加 3 列吗,这样我就有 4 列,每列 2000 个字符,从而获得 8000 个字符。因此,当第一列已满时,值将溢出到下一列,依此类推。这样的设计会不会有什么不好的副作用呢?请建议。

We have a table in Oracle 11g with a varchar2 column. We use a proprietary programming language where this column is defined as string. Maximum we can store 2000 characters (4000 bytes) in this column. Now the requirement is such that the column needs to store more than 2000 characters (in fact unlimited characters). The DBAs don't like BLOB or LONG datatypes for maintenance reasons.

The solution that I can think of is to remove this column from the original table and have a separate table for this column and then store each character in a row, in order to get unlimited characters. This tble will be joined with the original table for queries.

Is there any better solution to this problem?

UPDATE: The proprietary programming language allows to define variables of type string and blob, there is no option of CLOB. I understand the responses given, but I cannot take on the DBAs. I understand that deviating from BLOB or LONG will be developers' nightmare, but still cannot help it.

UPDATE 2: If maximum I need is 8000 characters, can I just add 3 more columns so that I will have 4 columns with 2000 char each to get 8000 chars. So when the first column is full, values would be spilled over to the next column and so on. Will this design have any bad side effects? Please suggest.

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

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

发布评论

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

评论(6

娜些时光,永不杰束 2024-09-11 16:27:23

如果您需要一个 blob,请说服您的 dba 这就是您所需要的。这些数据类型的存在是有原因的,任何自己动手的实现都会比内置类型更糟糕。

另外,您可能想查看 CLOB 类型,因为它可以很好地满足您的需求。

If a blob is what you need convince your dba it's what you need. Those data types are there for a reason and any roll your own implementation will be worse than the built in type.

Also you might want to look at the CLOB type as it will meet your needs quite well.

瞳孔里扚悲伤 2024-09-11 16:27:23

您可以遵循 Oracle 在信息模式中存储存储过程的方式。定义一个名为文本列的表:

CREATE TABLE MY_TEXT (
IDENTIFIER INT, 
LINE       INT,
TEXT       VARCHAR2 (4000),
PRIMARY KEY (INDENTIFIER, LINE));

标识符列是原始表的外键。 Line 是一个简单的整数(不是序列),用于保持文本字段的顺序。这允许保留更大的数据块

是的,这不如 blob、clob 或 LONG 高效(如果可能的话,我会避免使用 LONG 字段)。是的,这需要更多维护,但如果您的 DBA 坚决反对管理数据库中的 CLOB 字段,那么这是选项二。

编辑:

下面的 My_Table 是您当前要扩展的 VARCHAR 列的位置。我会将其保留在短文本字段的表格中。

CREATE TABLE MY_TABLE (
INDENTIFER INT,
OTHER_FIELD VARCHAR2(10),
REQUIRED_TEXT VARCHAR(4000),
PRIMERY KEY (IDENTFIER));

然后编写查询来拉取数据连接两个表,按 MY_TEXT 字段中的 LINE 排序。您的应用程序需要将字符串拆分为 2000 个字符块,并按行顺序插入它们。

我会在 PL/SQL 过程中执行此操作。既可以插入也可以选择。 PL/SQL VARCHAR 字符串最多可达 32K 个字符。它可能足够大,也可能不够大以满足您的需求。

但就像回答这个问题的其他人一样,我强烈建议 DBA 将该列设为 CLOB。从程序的角度来看,这将是一个 BLOB,因此易于管理。

You could follow the way Oracle stored their stored procedures in the information schema. Define a table called text columns:

CREATE TABLE MY_TEXT (
IDENTIFIER INT, 
LINE       INT,
TEXT       VARCHAR2 (4000),
PRIMARY KEY (INDENTIFIER, LINE));

The identifier column is the foreign key to the original table. The Line is a simple integer (not a sequence) to keep the text fields in order. This allows keeping larger chunks of data

Yes this is not as efficient as a blob, clob, or LONG (I would avoid LONG fields if at all possible). Yes, this requires more mainenance, buf if your DBAs are dead set against managing CLOB fields in the database, this is option two.

EDIT:

My_Table below is where you currently have the VARCHAR column you are looking to expand. I would keep it in the table for the short text fields.

CREATE TABLE MY_TABLE (
INDENTIFER INT,
OTHER_FIELD VARCHAR2(10),
REQUIRED_TEXT VARCHAR(4000),
PRIMERY KEY (IDENTFIER));

Then write the query to pull the data join the two tables, ordering by LINE in the MY_TEXT field. Your application will need to split the string into 2000 character chunks and insert them in line order.

I would do this in a PL/SQL procedure. Both insert and select. PL/SQL VARCHAR strings can be up to 32K characters. Which may or may not be large enough for your needs.

But like every other person answering this question, I would strongly suggest making a case to the DBA to make the column a CLOB. From the program perspective this will be a BLOB and therefore simple to manage.

嗳卜坏 2024-09-11 16:27:23

你说没有 BLOB 或 LONG...但是 CLOB 呢? 4GB 字符数据。

You said no BLOB or LONG... but what about CLOB? 4GB character data.

时间你老了 2024-09-11 16:27:23

BLOB 是最好的解决方案。其他任何事情都会不太方便,并且会带来更大的维护烦恼。

BLOB is the best solution. Anything else will be less convenient and a bigger maintenance annoyance.

安静被遗忘 2024-09-11 16:27:23

BFILE 对于 DBA 来说是一个可行的替代数据类型吗?

Is BFILE a viable alternative datatype for your DBAs?

在巴黎塔顶看东京樱花 2024-09-11 16:27:23

我不明白。 CLOB 是适当的数据库数据类型。如果你的奇怪的编程语言要处理 8000 个(或其他)字符的字符串,那么什么会阻止它将这些字符写入 CLOB。

更具体地说,当您尝试将 8000 个字符串插入定义为 CLOB 的列时,会出现什么错误(来自 Oracle 或您的编程语言)。

I don't get it. A CLOB is the appropriate database datatype. If your weird programming language will deal with strings of 8000 (or whatever) characters, what stops it writing those to a CLOB.

More specifically, what error do you get (from Oracle or your programming language) when you try to insert an 8000 character string into a column defined as a CLOB.

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