0
SELECT A.ID,LISTAGG(distinct PURCHASE_ID|| ':'||PURCHASE_AMT,',')WITHIN GROUP
        (ORDER BY PURCHASE_ID|| ':'||PURCHASE_AMT) as PURCHASE_INFO_TXT
from table_1 A
JOIN table_2 B
ON B.ORD_ID=A.ORD_ID
WHERE 
B.DATE = '2022-03-03'
AND PURCHASE_CD NOT IN ('0','1','2','2')
AND A.ID IN(90818774,90818789,90818999)
GROUP BY A.ID

When I run the above query, I'm getting the below results.

ID           PURCHASE_INFO_TXT
90818789     2028805453:$19.00 off when you buy 1 
90818774     2028805443:Save $6.00 when you buy 1
90818999     2028805403:$3.94 Each

The results should look like as mentioned below:

ID           PURCHASE_INFO_TXT

90818789     2028805453:$19.00
90818774     2028805443:$6.00
90818999     2028805403:$3.94

How to achieve this?

1 Answer 1

1

this may work for you using REGEXP_REPLACE.

select column1, fld1,REGEXP_REPLACE(fld1, '[^0-9_$:]') from (
  select column1,regexp_replace(column1,'when you buy 1','') fld1  from values 
  ('2028805453:$19.00 off when you buy 1 ') ,
  ('2028805443:Save $6.00 when you buy 1'), 
  ('2028805403:$3.94 Each') 
)  ;
Sign up to request clarification or add additional context in comments.

2 Comments

The decimal values are not coming correctly. Could you please guide on that? Thanks in advance!
@jenifer , this should work select column1, fld1,REGEXP_REPLACE(fld1, '[^0-9._$:]') from ( select column1,regexp_replace(column1,'when you buy 1','') fld1 from values ('2028805453:$19.00 off when you buy 1 ') , ('2028805443:Save $6.00 when you buy 1'), ('2028805403:$3.94 Each') ) ;

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.