如何在Oracle SQL中使用空字符串的电子邮件中替换@之前的所有点?

时间:2015-11-28 12:58:59

标签: sql oracle

我希望在oracle查询中使用dots的电子邮件中替换 @之前的所有empty string

喜欢:

anurag.mart@hotmail.com >> anuragmart@hotmail.com

2 个答案:

答案 0 :(得分:3)

最简单的方法是使用 REGEXP_REPLACE 来识别模式并将其替换为所需的模式。

<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>

例如,

regexp_replace('anurag.mart@hotmail.com', '(\w+)\.(\w+)(@+)', '\1\2\3')

答案 1 :(得分:2)

  • Instr - 识别位置(@
  • Substr - 在开始(1)和结束(@)位置之间提取数据
  • 替换 - 将.替换为''
  • || - 连接两个字符串

试试这个

SELECT Replace(Substr('anurag.mart@hotmail.com', 1, 
                      Instr('anurag.mart@hotmail.com', '@', 1)), '.', '') 
       || Substr('anurag.mart@hotmail.com', Instr('anurag.mart@hotmail.com','@')+1) 
FROM   dual 

<强>结果:

anuragmart@hotmail.com

SqlFiddle Demo