删除pl / sql中特定字符之间的字符

时间:2017-06-10 14:40:29

标签: sql oracle

我需要从下面的示例中获取子字符串

  

luvi.luci@gma

我想要返回luci。所以基本上我需要在''之前删除所有信息。在'@'之后

更多例子:

  

pd.prd@gded

2 个答案:

答案 0 :(得分:0)

您可以使用regexp_substr()执行此操作。这是一个例子:

select translate(regexp_substr(email, '[.].*@', 1, 1), 'x.@', 'x')
from (select 'luvi.luci@gma' as email from dual) x

答案 1 :(得分:0)

with data (val) as 
(
  select null from dual union all
  select 'luvi.luci' from dual union all
  select 'luvi.luci@gma' from dual union all
  select 'pd.prd@gded' from dual
)
-- step:1 
-- find the second group (\2) within the match 
-- ie. (any word/sequence of characters (\w+) flanked by a dot and a @)
-- step:2 
-- |.   OR any other character not matched in step:1 - will be ignored
-- step:3
-- \2   for each match found while parsing, for the entire match, 
--      replace it with the second group - so the dot and the @ are dropped from the match
select val, regexp_replace (val, '(\.(\w+)@)|.', '\2') ss from data;