首页 > 解决方案 > 使用 sql 查询获取 clob 字段中的每一行

问题描述

我在由多行数据组成的表中有一个 clob 字段。我想从此字段中获取特定行。

数据是如下所示的字段:

Project xxxxxx.
Reschedule Details:
Current Planned End Date: xxxxx
Adjusted Planned End Date: xxxxx
Current Forecasted Date: xxxxx
Reason: xxxxx – xxxxx
Comments: xxxxx

我的要求是获取原因和评论行数据。

标签: oracleoracle12c

解决方案


REGEXP_SUBSTR与多行选项一起使用,m这意味着字符串中的换行符终止一行。因此,行首锚 ( ^) 和行尾锚 ( $) 可用于终止。

select regexp_substr(s,'Reason:\s*(.+)$'  ,1,1,'m',1) as Reason,
       regexp_substr(s,'Comments:\s*(.+)$',1,1,'m',1) as Comments
       from t

演示


推荐阅读