Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String r溶液 Thi[$] is a strin[$] I am [$]ew to Or[$]cle with rcte(str, sigils, occ) as ( select 'Thi[$] is a strin[$] I am [$]ew to O_String_Oracle_Loops_Replace_Regexp Replace - Fatal编程技术网

String r溶液 Thi[$] is a strin[$] I am [$]ew to Or[$]cle with rcte(str, sigils, occ) as ( select 'Thi[$] is a strin[$] I am [$]ew to O

String r溶液 Thi[$] is a strin[$] I am [$]ew to Or[$]cle with rcte(str, sigils, occ) as ( select 'Thi[$] is a strin[$] I am [$]ew to O,string,oracle,loops,replace,regexp-replace,String,Oracle,Loops,Replace,Regexp Replace,r溶液 Thi[$] is a strin[$] I am [$]ew to Or[$]cle with rcte(str, sigils, occ) as ( select 'Thi[$] is a strin[$] I am [$]ew to Or[$]cle' as str , 'sgna' as sigils , 0 as occ from dual union all select substr(str, 1, instr(s

r溶液
Thi[$] is a strin[$] I am [$]ew to Or[$]cle
with rcte(str, sigils, occ) as (
  select 'Thi[$] is a strin[$] I am [$]ew to Or[$]cle' as str
          , 'sgna' as sigils
          , 0 as occ 
  from dual
  union all
  select substr(str, 1, instr(str,'[$]',1,1)-1)||substr(sigils, occ+1, 1)||substr(str, instr(str,'[$]',1,1)+3) as str
         , sigils
         , occ+1 as occ
  from rcte
  where occ <= length(sigils)
)
select * 
from rcte
where occ = length(sigils)
-- First CTE just sets up source data
WITH tbl(str) AS (
  SELECT 'Thi[$] is a strin[$] I am [$]ew to Or[$]cle' FROM dual
),
-- Lookup table.  Does not have to be a CTE here, but a normal table
-- in the database.
tbl_sub_values(ID, VALUE) AS (
  SELECT 1, 's' FROM dual UNION ALL
  SELECT 2, 'g' FROM dual UNION ALL
  SELECT 3, 'n' FROM dual UNION ALL
  SELECT 4, 'a' FROM dual
),
-- Split the source data using the placeholder as a delimiter
tbl_split(piece_id, str) AS (
  SELECT LEVEL AS piece_id, REGEXP_SUBSTR(t.str, '(.*?)(\[\$\]|$)', 1, LEVEL, NULL, 1) 
  FROM tbl T
  CONNECT BY LEVEL <= REGEXP_COUNT(t.str, '[$]') + 1
)
-- select * from tbl_split;
-- Put the string back together, joining with the lookup table
SELECT LISTAGG(str||tsv.value) WITHIN GROUP (ORDER BY piece_id) STRING
FROM tbl_split ts
  LEFT JOIN tbl_sub_values tsv
    ON ts.piece_id = tsv.id;

STRING                                                                          
--------------------------------------------------------------------------------
This is a string I am new to Oracle