有一种方法可以转置两个字符串并得到 table 作为结果吗?

there is a way to transpose two strings and have a table as result?

我有接下来的两个字符串:

String_Cod   = 14521;65412;65845
String_Flags = 1;0;1


for code 14521 the flag is 1
for code 65412 the flag is 0
for code 65845 the flag is 1
in this order always

结果必须类似于

我从这个查询开始:

select regexp_substr(to_char(:STRING_COD),'[^;]+', 1, level)
from dual
connect BY regexp_substr(to_char(:STRING_COD), '[^;]+', 1, level)
is not null

select regexp_substr(to_char(:STRING_FLAGS),'[^;]+', 1, level)
from dual
connect BY regexp_substr(to_char(:STRING_FLAGS), '[^;]+', 1, level)
is not null

但我不知道如何继续加入两者并获得我需要的结果。

有人可以给个建议吗?

此致

您可以在每个查询中将级别添加为另一列,并将它们连接在一起:

select c.cod, f.flag
from (
  select level as n, regexp_substr(to_char('14521;65412;65845'),'[^;]+', 1, level) as cod
  from dual
  connect BY regexp_substr(to_char('14521;65412;65845'), '[^;]+', 1, level)
  is not null
) c
join (
  select level as n, regexp_substr(to_char('1;0;1'),'[^;]+', 1, level) as flag
  from dual
  connect BY regexp_substr(to_char('1;0;1'), '[^;]+', 1, level)
  is not null
) f
on f.n = c.n

其中 - 使用外连接 - 将允许不同数量的元素;或者更简单地说,正如您所建议的那样,它们将始终匹配,对两个提取物使用相同的级别:

select regexp_substr(to_char('14521;65412;65845'),'[^;]+', 1, level) as cod,
  regexp_substr(to_char('1;0;1'),'[^;]+', 1, level) as flag
from dual
connect BY regexp_substr(to_char('14521;65412;65845'), '[^;]+', 1, level)
is not null
COD   | FLAG
:---- | :---
14521 | 1   
65412 | 0   
65845 | 1   

db<>fiddle

这种扩展值列表的方法还假定您在任何一个列表中都不能有空元素。