Oracle中的regexp_substr文字最大长度限制

发布于 2025-01-18 01:38:42 字数 330 浏览 2 评论 0原文

我需要提取文本中以分号分隔的值。 我使用 regexp_substr ,它非常强大,但字符串有限制。我有时有一个包含 10 000 个字符的文本,因此不可能在此 inbuild 函数中使用此类字符串。

文字看起来像这样 - AU783 343; 3N9493 ;113 UN9 WE3 54 ; OI8343,; 43U.783.3

只有 0-9 和 AZ ,如果有冒号或句点则应删除。输出必须保持原样,但没有前导和尾随空格,

AU783 343
3N9493
113 UN9 WE3 54
OI8343
43U7833

有什么建议如何避免最大长度限制?

I need to extract values delimited by semicolon in a text.
I use regexp_substr which is very powerful but the string has a limit. I have sometimes a text with 10 000 characters so is not possible to use such string in this inbuild function.

the text looks like this - AU783 343; 3N9493 ;113 UN9 WE3 54 ; OI8343, ; 43U.783.3

just 0-9 and A-Z , if there is a colon or period then it should be deleted. the output must be as it is but withou leading and trailing spaces

AU783 343
3N9493
113 UN9 WE3 54
OI8343
43U7833

any suggestion how to avoid the max length limit?

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

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

发布评论

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

评论(1

涫野音 2025-01-25 01:38:42

您不需要使用正则表达式。简单的字符串函数 SUBSTRINSTRREPLACE 就足够了,并且可以使用 CLOB 值。

例如,给定表:

CREATE TABLE table_name (
  id    NUMBER
        GENERATED ALWAYS AS IDENTITY
        PRIMARY KEY,
  value CLOB
);

您可以使用以下方法提取所有子字符串:

WITH bounds (id, value, s_pos, e_pos) AS (
  SELECT id,
         value,
         1,
         INSTR(value, ';', 1)
  FROM   table_name
UNION ALL
  SELECT id,
         value,
         e_pos + 1,
         INSTR(value, ';', e_pos + 1)
  FROM   bounds
  WHERE  e_pos > 0
)
SEARCH DEPTH FIRST BY id SET id_order
SELECT id,
       REPLACE(
         REPLACE(
           CASE e_pos
           WHEN 0
           THEN SUBSTR(value, s_pos)
           ELSE SUBSTR(value, s_pos, e_pos - s_pos)
           END,
           ':'
         ),
         '.'
       ) AS value
FROM   bounds;

请参阅 db< >fiddle 是一个非常大的字符串的例子。

You don't need to use regular expressions. The simple string functions SUBSTR, INSTR and REPLACE are sufficient and work with CLOB values.

For example, given the table:

CREATE TABLE table_name (
  id    NUMBER
        GENERATED ALWAYS AS IDENTITY
        PRIMARY KEY,
  value CLOB
);

You can extract all the substrings using:

WITH bounds (id, value, s_pos, e_pos) AS (
  SELECT id,
         value,
         1,
         INSTR(value, ';', 1)
  FROM   table_name
UNION ALL
  SELECT id,
         value,
         e_pos + 1,
         INSTR(value, ';', e_pos + 1)
  FROM   bounds
  WHERE  e_pos > 0
)
SEARCH DEPTH FIRST BY id SET id_order
SELECT id,
       REPLACE(
         REPLACE(
           CASE e_pos
           WHEN 0
           THEN SUBSTR(value, s_pos)
           ELSE SUBSTR(value, s_pos, e_pos - s_pos)
           END,
           ':'
         ),
         '.'
       ) AS value
FROM   bounds;

See db<>fiddle for an example with very large strings.

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