Oracle 11g 中字符溢出到多个列?

发布于 2024-09-04 19:54:29 字数 292 浏览 9 评论 0原文

这与问题相关:如何在 Oracle 11g 中存储无限字符?< /a>

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

This is related to question: How to store unlimited characters in Oracle 11g?

If maximum I need is 8000 characters, can I just add 3 more varchar2 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技术交流群

发布评论

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

评论(3

时光清浅 2024-09-11 19:54:29

为什么不直接使用 CLOB 列呢?我读了您的其他链接,但我不明白为什么您的 DBA 不喜欢这些类型的列。我的意思是,CLOB 是 Oracle 的一个重要功能,正是为了这个目的。您的公司在购买 Oracle 时为该功能付出了很多钱,那么为什么不充分利用 Oracle 的功能,而不是尝试想出一些技巧来完成数据库并非真正设计要做的事情呢?

也许您不应该花时间尝试设计技巧来克服 DBA 造成的限制,而应该花一些时间教育您的 DBA 为什么 CLOB 是解决您的问题的正确功能。

当数据库具有我需要进行良好设计的功能时,我永远不会满足于糟糕的设计。如果 DBA 是问题所在,那么他们需要改变观点,或者我认为您应该去找高级管理层。

Why not just use a CLOB column instead? I read your other link, and I don't understand why your DBA's don't like these types of columns. I mean, CLOB is an important feature of Oracle just for this exact purpose. And your company paid good money for that feature when buying Oracle, so why not leverage Oracle to it's fullest capabilities instead of trying to come up with hacks to do something that the DB is not really designed to do?

Maybe instead of spending time trying to devise hacks to overcome limitations created by your DBAs, you should spend some time educating your DBA's on why CLOBs are the right feature to solve your problem.

I would never be satisfied with a bad design when the DB has the feature I need to make a good design. If the DBA's are the problem, then they need to change their viewpoint or you should go to senior level management in my opinion.

新一帅帅 2024-09-11 19:54:29

我同意 dcp 的观点,即您应该使用 CLOB。但是如果与所有意义上的相反,您被迫仅使用 VARCHAR2 列“滚动自己的”无限文本,那么我不会通过向表中添加越来越多的 VARCHAR2 列来实现这一点,如下所示:

create table mytable
  ( id integer primary key
  , text varchar2(2000)
  , more_text varchar2(2000)
  , and_still_more_text varchar2(2000)
  );

相反,我会移动 然后,

create table mytable
  ( id integer primary key
  );
create table mytable_text
  ( id references mytable(id)
  , seqno integer
  , text varchar2(2000)
  , primary key (id, seqno)
  );

您可以使用 mytable_text 中的许多行,为每个 mytable 行插入任意多的文本。

I agree with dcp that you should be using CLOB. But if against all sense you are forced to "roll your own" unlimited text using just VARCHAR2 columns then I would not do it by adding more and more VARCHAR2 columns to the table like this:

create table mytable
  ( id integer primary key
  , text varchar2(2000)
  , more_text varchar2(2000)
  , and_still_more_text varchar2(2000)
  );

Instead I would move the text to a separate child table like this:

create table mytable
  ( id integer primary key
  );
create table mytable_text
  ( id references mytable(id)
  , seqno integer
  , text varchar2(2000)
  , primary key (id, seqno)
  );

Then you can insert as much text as you like for each mytable row, using many rows in mytable_text.

空气里的味道 2024-09-11 19:54:29

对 DCP 和 Tony 的出色回答进行补充:

您询问您提出的方法是否会产生任何不良副作用。以下是需要考虑的一些事项:

  1. 假设您想要在文本数据中搜索特定字符串。您的方法需要对包含文本的每一列重复搜索 - 导致 WHERE 子句复杂且低效。
  2. 每次您想要扩展文本字段时,您都必须添加另一列,这意味着您现在必须修改编码要做的每个位置 (1)。
  3. 在你之后必须维持这个结构的每个人都会诅咒你的名字;-)

To add to DCP's and Tony's excellent answers:

You ask if the approach you are proposing will have any bad side effects. Here are a few things to consider:

  1. Suppose you want to perform a search of your text data for a particular string. Your approach requires repeating the search on each column containing your text - results in a convoluted and inefficient WHERE clause.
  2. Every time you want to expand your text field you have to add another column, which now means you have to modify every place you coded to do (1).
  3. Everyone who has to maintain this structure after you will curse your name ;-)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文