WITH code AS ( SELECT 'A' cd, 80.7 v FROM dual UNION ALL SELECT 'B', 79.2 FROM dual UNION ALL SELECT 'C', 78.0 FROM dual UNION ALL SELECT 'D', 81.7 FROM dual UNION ALL SELECT 'E', 71.5 FROM dual UNION ALL SELECT 'F', 74.7 FROM dual UNION ALL SELECT 'G', 74.5 FROM dual UNION ALL SELECT 'H', 74.5 FROM dual UNION ALL SELECT 'I', 74.0 FROM dual UNION ALL SELECT 'J', 75.5 FROM dual ) , calc AS ( SELECT 1 id, 'A+B+((C/D) * E)' x FROM dual UNION ALL SELECT 2, '(A+B+C+D+E+F+G+H+I+J)/10' FROM dual ) , tmp AS ( SELECT a.id , a.x , b.cd , b.v , ROW_NUMBER() OVER(PARTITION BY a.id ORDER BY b.cd) rn , COUNT(*) OVER(PARTITION BY a.id) cnt FROM calc a , code b WHERE INSTR(a.x, b.cd) > 0 ) , rec(id, x, cnt, rn, y) AS ( SELECT id, x, cnt , rn , REPLACE(x, cd, v) y FROM tmp WHERE rn = 1 UNION ALL SELECT a.id, a.x, a.cnt , b.rn , REPLACE(a.y, b.cd, b.v) y FROM rec a , tmp b WHERE b.id = a.id AND b.rn = a.rn + 1 ) SELECT id , x , y , TO_NUMBER( dbms_xmlgen.getxmltype('SELECT ' || y || ' FROM dual').Extract('//text()') ) z FROM rec WHERE cnt = rn ;