首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在oracle中获取给定字符串之间的字符串

如何在oracle中获取给定字符串之间的字符串
EN

Stack Overflow用户
提问于 2019-10-09 20:20:44
回答 3查看 42关注 0票数 1

这就是我的数据的样子。

代码语言:javascript
复制
APP_APX_PLM_PostCategory~~~pavan anand~~~2019-09-26 15:03:39@@@MF_APX_PLM_PostBuyProgram.msgflow***MF_APX_PLM_PostBuyProgram1.msgflow***MF_APX_PLM_PostBuyProgram2.msgflow^^^APP_APX_PLM_Promo~~~skola2
~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow^^^APP_APX_PLM_Santosh~~~skola2~~~2019-09-30 14:39:26@@@MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow***MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow

我想要获得从第一个字符到第一次出现^的数据,以及从第一个^^到第二个^^的数据。

有谁能帮我把这个放到甲骨文里吗?

EN

回答 3

Stack Overflow用户

发布于 2019-10-09 20:33:56

使用REGEXP_SUBSTR

https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=0981e7232b873934c5d4e833c141f47a

代码语言:javascript
复制
with tbl as 
(select 'APP_APX_PLM_PostCategory~~~pavan anand~~~2019-09-26 15:03:39@@@MF_APX_PLM_PostBuyProgram.msgflow***MF_APX_PLM_PostBuyProgram1.msgflow***MF_APX_PLM_PostBuyProgram2.msgflow^^^APP_APX_PLM_Promo~~~skola2~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow^^^APP_APX_PLM_Santosh~~~skola2~~~2019-09-30 14:39:26@@@MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow***MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow' str 
from dual)
select TRIM( '^' FROM REGEXP_SUBSTR(str, '.+?\^{3}')),
TRIM( '^' FROM REGEXP_SUBSTR(str, '\^{3}.+?\^{3}',1,1,'n'))  from tbl

输出

代码语言:javascript
复制
APP_APX_PLM_PostCategory~~~pavan anand~~~2019-09-26 15:03:39@@@MF_APX_PLM_PostBuyProgram.msgflow***MF_APX_PLM_PostBuyProgram1.msgflow***MF_APX_PLM_PostBuyProgram2.msgflow  APP_APX_PLM_Promo~~~skola2~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow
票数 0
EN

Stack Overflow用户

发布于 2019-10-09 20:47:20

只需在弹出窗口时复制字符串或替换为:str

代码语言:javascript
复制
select 
substr(:str,
instr(:str,'^^^',1,1) +3,
instr(:str,'^^^',1,2) - instr(:str,'^^^',1,1) - 3)
from dual;
票数 0
EN

Stack Overflow用户

发布于 2019-10-09 21:02:01

我将以一种不同的方式来处理它,并假设您正准备解析这个多分隔字符串。由于第一级分隔似乎是通过'^^^'进行的,因此让我们使用connect by遍历字符串并拆分出这些元素,只返回前2个元素,因为这是您的要求。这将返回由'^^^'分隔的前2个元素

代码语言:javascript
复制
with tbl(str) as (
  select 'APP_APX_PLM_PostCategory~~~pavan anand~~~2019-09-26 15:03:39@@@MF_APX_PLM_PostBuyProgram.msgflow***MF_APX_PLM_PostBuyProgram1.msgflow***MF_APX_PLM_PostBuyProgram2.msgflow^^^APP_APX_PLM_Promo~~~skola2~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow^^^APP_APX_PLM_Santosh~~~skola2~~~2019-09-30 14:39:26@@@MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow***MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow' str 
  from dual
)
select regexp_substr(str, '(.*?)(\^\^\^|$)', 1, level, NULL, 1) element
from tbl
connect by level <= 2; --regexp_count(str, '\^\^\^')+1;

注如果您只想要一个特定的元素,请将regexp_substr调用中的"level“替换为该元素的编号。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58304020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档