Link to home
Start Free TrialLog in
Avatar of PresidentLincoln
PresidentLincolnFlag for United States of America

asked on

DB2: Need to extract last 3 characters of a string

I need to extract a set of numbers from a string in a DB2 query.  The string length will vary, but the numbers I will need to extract will always be the last 3 numbers, and they will always follow the same text pattern.  For example, I have a string that looks like this:

CustomerNumber=5555555|IndividualNumber=999 

Open in new window


The "CustomerNumber" itself could be anywhere from 3 to 20 numbers (5555555 in this case), but the "IndividualCode" will always be 3 numbers (999 in this case), and will always be preceded by the pipe and the string "IndividualNumber=".

So I need to be able to write a SELECT query in DB2 that will just give me the last 3 numbers of that entire string.  I might have given too much info here to say "how do I always extract the last 3 numbers of this string", but I wanted to err on the side of caution.

Just FYI, I am using an AIX database and IBM Data Studio 4.1.3.
ASKER CERTIFIED SOLUTION
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PresidentLincoln

ASKER

Okay, a little embarrassed how easy that was, but thank you!  I was going down the REGEXP_EXTRACT path and that's where I was running into issues.