简体   繁体   English

从 oracle 中的 clob 列中提取数据

[英]extract data from clob column in oracle

I am having data in clob column as below:我在 clob 列中有如下数据:

:1A:CAD22021828,17
:1B:RECEIVE GENERAL IND
11 BEGUM ST 3-15A2
  VILL              AP IND 313 416
:1C:/000061071257      CC
RECEIVER GENERAL FOR IND
C/O PNBB MAIN BRANCH
11 BEGUM ST 3-15A2
AA HYD         APIND

Now my requirement is to load this into 3 separate columns in target table as below:现在我的要求是将其加载到目标表中的 3 个单独的列中,如下所示:

1A    - CAD22021828,17
1B    - RECEIVE GENERAL IND 
        11 BEGUM ST 3-15A2
        VILL              AP IND 313 416
1C    - /000061071257      CC
        RECEIVER GENERAL FOR IND
        C/O PNBB MAIN BRANCH
        11 BEGUM ST 3-15A2
        AA HYD         APIND

can someone suggest how I can do this.有人可以建议我如何做到这一点。

This is oracle 11.2这是 oracle 11.2

I have tried below code;我试过下面的代码;

SELECT
    REGEXP_SUBSTR(mc_clob,':1A:([[:alnum:]]+\S+)') AS code1A,
    REGEXP_SUBSTR(mc_clob,':1B:([[:alnum:]]+\s+)') AS code1B,
    REGEXP_SUBSTR(mc_clob,':1C:([[:alnum:]]+\s+)') AS code1c
FROM tableA;

Here is one way to do this using REGEXP_SUBSTR with capture groups:这是使用带有捕获组的REGEXP_SUBSTR执行此操作的一种方法:

SELECT
    REGEXP_SUBSTR(mc_clob, ':1A:(.*):1B:', 1, 1, 'n', 1) AS code1A,
    REGEXP_SUBSTR(mc_clob,':1B:(.*):1C:', 1, 1, 'n', 1) AS code1B,
    REGEXP_SUBSTR(mc_clob,':1C:(.*)', 1, 1, 'n', 1) AS code1c
FROM tableA;

演示结果集的屏幕截图

Demo 演示

To understand how this works, take the first call to REGEXP_SUBSTR :要了解它是如何工作的,请首先调用REGEXP_SUBSTR

REGEXP_SUBSTR(mc_clob, ':1A:(.*):1B:', 1, 1, 'n', 1)

This says to match :1A:(.*):1B: , capturing all content between the :1A: and :1B: markers.这表示匹配:1A:(.*):1B: ,捕获:1A::1B:标记之间的所有内容。 The fifth parameter is n , which tells Oracle to let dot match across newlines.第五个参数是n ,它告诉 Oracle 让点匹配跨换行符。 That is, (.*) will capture all content between the two markers, including across lines.也就是说, (.*)将捕获两个标记之间的所有内容,包括跨行。 The sixth parameter is 1 , which means that the return value will be the first (and only) capture group.第六个参数是1 ,这意味着返回值将是第一个(也是唯一一个)捕获组。 Similar logic applies to the second and third call to REGEXP_SUBSTR .类似的逻辑适用于对REGEXP_SUBSTR的第二次和第三次调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM