I want to replace all the dots
before @
in an email with empty string
in oracle query
like:
anurag.mart@hotmail.com >> anuragmart@hotmail.com
I want to replace all the dots
before @
in an email with empty string
in oracle query
like:
anurag.mart@hotmail.com >> anuragmart@hotmail.com
The easiest way is to use REGEXP_REPLACE to identify the pattern and replace it with required pattern.
regexp_replace('anurag.mart@hotmail.com', '(\w+)\.(\w+)(@+)', '\1\2\3')
For example,
SQL> SELECT 'anurag.mart@hotmail.com' email_id,
2 regexp_replace('anurag.mart@hotmail.com', '(\w+)\.(\w+)(@+)', '\1\2\3') new_email_id
3 FROM dual;
EMAIL_ID NEW_EMAIL_ID
----------------------- ----------------------
anurag.mart@hotmail.com anuragmart@hotmail.com
@
)1
) and end(@
) position.
with ''
Try this
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
Result:
anuragmart@hotmail.com
I came on this page while looking for solutions for SQL servers, I converted the above for SQL server for my project, Here is SQL if anybody else needs it.
SELECT
CONCAT(
REPLACE(
SUBSTRING(EmailAddress, 1, CHARINDEX('@', EmailAddress)-1),
'.',
''
),
SUBSTRING(EmailAddress, CHARINDEX('@', EmailAddress), LEN(EmailAddress))
)
FROM [Applicant]