Sql 字符串stringtokenizer的Oracle函数

Sql 字符串stringtokenizer的Oracle函数,sql,regex,oracle,split,Sql,Regex,Oracle,Split,我不熟悉oraclepl/SQL。我需要创建函数来标记下面的字符串 test|1$test2|4$test4|5$test9|3 下排 Key value test 1 test2 4 test4 5 test9 3 谢谢您不需要PL/SQL函数,SQL可以做到这一点: SQL> with 2 -- input string 3 test (col) as 4 (select 'test|1$test2|4$test4|5$test9|3

我不熟悉oraclepl/SQL。我需要创建函数来标记下面的字符串

test|1$test2|4$test4|5$test9|3
下排

Key   value 
test    1
test2   4
test4   5
test9   3 

谢谢

您不需要PL/SQL函数,SQL可以做到这一点:

SQL> with
  2  -- input string
  3  test (col) as
  4    (select 'test|1$test2|4$test4|5$test9|3' from dual),
  5  -- intermediate CTE which creates rows
  6  inter as
  7    (select regexp_substr(col, '[^$]+', 1, level) val
  8     from test
  9     connect by level <= regexp_count(col, '\$') + 1
 10    )
 11  -- create two columns out of each substring
 12  select substr(val, 1, instr(val, '|') - 1) key,
 13         substr(val, instr(val, '|') + 1) value
 14  from inter;

KEY        VALUE
---------- ----------
test       1
test2      4
test4      5
test9      3

SQL>

但是,如果必须是函数,那么将上述代码转换为函数应该不会太困难。

到目前为止您尝试了什么?提示:通过regex\u substr拆分记录。。然后插入,根据需要,函数将返回类型设置为Record,因为它是行和列的混合体