这就是我的数据的样子。
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我想要获得从第一个字符到第一次出现^的数据,以及从第一个^^到第二个^^的数据。
有谁能帮我把这个放到甲骨文里吗?
发布于 2019-10-09 20:33:56
使用REGEXP_SUBSTR
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=0981e7232b873934c5d4e833c141f47a
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输出
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发布于 2019-10-09 20:47:20
只需在弹出窗口时复制字符串或替换为:str
select
substr(:str,
instr(:str,'^^^',1,1) +3,
instr(:str,'^^^',1,2) - instr(:str,'^^^',1,1) - 3)
from dual;发布于 2019-10-09 21:02:01
我将以一种不同的方式来处理它,并假设您正准备解析这个多分隔字符串。由于第一级分隔似乎是通过'^^^'进行的,因此让我们使用connect by遍历字符串并拆分出这些元素,只返回前2个元素,因为这是您的要求。这将返回由'^^^'分隔的前2个元素
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“替换为该元素的编号。
https://stackoverflow.com/questions/58304020
复制相似问题