HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

CHARINDEX equivalent in DB2

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
equivalentcharindexdb2

Problem

I am trying to select the domain from the column where I have email addresses.

For example, I have a table email_table and a column email with email addresses as below.

johndoe@gmail.com
jhefid@yahoo.com
ipw@gmx.com


Expected result

gmail.com
yahoo.com
gmx.com


Here is the query I tried with CHARINDEX that works in SQL Server but not in DB2.

select CHARINDEX('@', email) from email_table

Solution

It's LOCATE (in DB2) which is equivalent to CHARINDEX in SQL Server.

Here is the complete description of it with example.

Thanks!

Context

StackExchange Database Administrators Q#243145, answer score: 3

Revisions (0)

No revisions yet.