【问题标题】:SQL ORACLE SUBSTRINGSQL ORACLE 子字符串
【发布时间】:2018-01-03 14:13:27
【问题描述】:

我在这样的列中有多个 email_id:

aaaaaa.bbbbb.cccc@xyz.com;mmmm.cccc@xyz.com;ppp.ddd.ssss@xyz.com
sssss.fffff@xyz.com
pppp.gggg@xyz.com;bbbb.kkk.ppp@xyz.com;nnn.ppp@xyz.com
uuuu.vvvvv@xyz.com

如果他们在列中有多个电子邮件 ID,我想收到第一封电子邮件。列中的每个 email_id 由“;”分隔。

【问题讨论】:

    标签: sql oracle substring


    【解决方案1】:

    您可以结合使用instrsubstr

    select case when instr(email,';') > 0 then substr(email,1,instr(email,';')-1) else email end as new_email_col
    from tablename
    

    【讨论】:

      【解决方案2】:

      我们也可以在这里使用REGEXP_SUBSTR

      SELECT REGEXP_SUBSTR (email, '([^;]*)') AS first
      FROM yourTable;
      

      Demo

      【讨论】:

      • 投反对票的人是否希望发表评论?一般来说,经过测试的功能代码不值得一票否决。
      猜你喜欢
      • 1970-01-01
      • 2019-03-19
      • 2019-02-06
      • 2021-04-14
      • 2020-12-06
      • 2018-03-14
      • 2014-10-22
      • 1970-01-01
      相关资源
      最近更新 更多