1

This is how my data look like.

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

I want to get the data from 1st character to 1st occurrence of ^^^ and also data from first ^^^ to the second ^^^.

Can anyone help me to get this in oracle?

4 Answers 4

2

Use INSTR to find the positions of the delimiters and then SUBSTR to extract the sub-strings:

Oracle Setup:

CREATE TABLE test_data ( value ) 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' FROM DUAL;

Query:

SELECT SUBSTR( value, 1, first_position - 1 ) AS first_substr,
       SUBSTR( value, first_position + 3, second_position - first_position - 3 ) AS second_substr
FROM   (
  SELECT value,
         INSTR( value, '^^^', 1, 1 ) AS first_position,
         INSTR( value, '^^^', 1, 2 ) AS second_position
  FROM   test_data
)

Output:

FIRST_SUBSTR                                                                                                                                                               | SECOND_SUBSTR                                                                                               
:------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----------------------------------------------------------------------------------------------------------
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<br>~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow

db<>fiddle here

Sign up to request clarification or add additional context in comments.

Comments

1

Use 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

output

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

Comments

1

I'm going to approach it a different way, and assume you are preparing to parse this multi-delimited string. Since the first level of delimiting seems to be by '^^^', let's use connect by to traverse the string and split out those elements, returning just the first 2 since that is your requirement. This returns the first 2 elements delimited by '^^^':

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;

Note if you only want a particular element, replace "level" in the regexp_substr call with the number of the element.

Comments

0

Just copy your string when window pops up or replace with :str

select 
substr(:str,
instr(:str,'^^^',1,1) +3,
instr(:str,'^^^',1,2) - instr(:str,'^^^',1,1) - 3)
from dual;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.