从半冒号分隔的字符串中获取不同的电子邮件

时间:2019-06-20 10:42:20

标签: plsql

我在plsql TBL_A,TBL_B和TBL_C中有三个表,我在每个表中都有email列,并且在该列中有多个以';'分隔的值,我想合并来自所有3个表的DISTINCT电子邮件值并将其存储在TBL_D,表结构如下

尝试过LISTAGG,但我对获取DISTINCT值感到困惑。

set :rails_env, 'production'

想要获得类似

的结果
TBL_A : Email(Varchar2(500)) : abc@test.com;xyz@test;com;pqr@test;com (sample data)

TBL_B : Email(Varchar2(500)) : cba@test.com;zyx@test;com;pqr@test;com (sample data)

TBL_C : Email(Varchar2(500)) : abc@test.com;xyz@test;com;pqr@test;com;klm@test.com (sample data)

并将其存储在表D的“电子邮件”列中。

2 个答案:

答案 0 :(得分:1)

具有正则表达式和listagg函数:

insert into tbl_d
      select listagg(emails.email, ';') within group(order by emails.email)
        from (select regexp_substr(a.email, '[^;]+', 1, level) email
                from tbl_a a
              connect by regexp_substr(a.email, '[^;]+', 1, level) is not null
              union
              select regexp_substr(a.email, '[^;]+', 1, level) email
                from tbl_b a
              connect by regexp_substr(a.email, '[^;]+', 1, level) is not null
              union
              select regexp_substr(a.email, '[^;]+', 1, level) email
                from tbl_c a
              connect by regexp_substr(a.email, '[^;]+', 1, level) is not null) emails

答案 1 :(得分:1)

这是@ tso的替代解决方案,它也使用正则表达式和listagg函数:

首先合并所有内容,然后将值拆分为行并最后汇总

func didReceive(_ element: Element) {

    data.append(element)
    onElementReceival(IndexPath(row:data.count, section: 0))

}
相关问题