Oracle multiple character substitution implementations

Source: Internet
Author: User


CREATE TABLE A_test
(
Payout_item_code VARCHAR2 () NOT NULL,
Formula_det VARCHAR2 (1000)
)
CREATE table

Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30228 ', ' ({30015}+{30016}) *450 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30102 ', ' ({30015}+{30016}) *1500 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30102 ', ' ({30015}+{30016}) *5000 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30102 ', ' ({30015}+{30016}) *2500 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30102 ', ' ({30015}+{30016}) *2300 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30102 ', ' ({30015}+{30016}) *1150 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30104 ', ' ({30015}+{30016}) *300*12 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30057}*2300 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30102 ', ' ({30015}+{30016}) *5000 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30102 ', ' ({30015}+{30016}) *3000 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30102 ', ' ({30015}+{30016}) *1500 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30006}+{30061}+{30008} ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30057}*3800*12 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30210 ', ' ({30030}+{30031}+{30032}) *38000+{30033}*23000 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30210 ', ' ({30030}+{30031}+{30032}+{30033}) *38000+{30036}*10000 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30229 ', ' ({30015}+{30016}) *1400 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30228 ', ' ({30015}+{30016}) *450 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30216 ', ' ({30015}+{30016}) *1300 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30216 ', ' ({30015}+{30016}) *650 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30307 ', ' ({30015}+{30016}) *360 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30302 ', ' {30051} ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30302 ', ' {30052} ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30302 ', ' {30053} ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30302 ', ' {30054} ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30302 ', ' {30055} ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30302 ', ' {30056} ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30057}*4000 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30057}*3800 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30057}*100*12 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30057}*500*12 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30060}*0 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30057}/{30057}*150000 ');
Insert into A_test (Payout_item_code, Formula_det)
VALUES (' 30226 ', ' {30057}*6000 ');


Select GID, Payout_item_code, Formula_det, Max (substr (TXT, 1, Length (TXT)-1)) from (
Select A.gid,
A.payout_item_code,
A.formula_det,
Replace (Sys_connect_by_path decode (b.element_id, NULL, a.signal, replace (signal, b.element_id, b.name)), ' # # ', ' # # ', ") txt
From
(select GID, Payout_item_code, Formula_det, Row_number () over (partition by GID Order by level) RN,
SUBSTR (Formula_det, Decode (rownum-(allcnt-selfcnt), 1, 1, InStr (Formula_det, '} ', 1, rownum-(allcnt-selfcnt)-1) +1), InStr (Formula_det, '} ', 1, rownum-(allcnt-selfcnt))-decode (rownum-(allcnt-selfcnt), 1, 0, InStr (Formula_det, '} ', 1, rownum-(allcnt-selfcnt)-1)) signal
From (select A.payout_item_code, A.rowid GID,
a.formula_det| | '} ' Formula_det,
Length (A.formula_det)-
Length (replace (A.formula_det, '} ', ')) + 1 selfcnt,
Sum (Length (a.formula_det)-Length (replace (A.formula_det, '} ', ')) (+1) over (order by ROWID) allcnt, sum (Length ( A.formula_det)-Length (replace (A.formula_det, '} ', ')) (+1) over () sumcnt
From A_test a) T1
Start with (allcnt-selfcnt) =0 Connect by RowNum < sumcnt+1 and InStr (Formula_det, '} ', 1, rownum-(allcnt-selfcnt)) > 0) A
Left join B_test B on InStr (a.signal| | '} ', ' {' | | b.element_id| | '} ', 1, 1 >0
Start with A.RN = 1 Connect by prior A.gid = A.gid and prior a.rn + 1 = a.rn)
GROUP by GID, Payout_item_code, Formula_det

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.