I have the below a varchar column called "Person_Info" in DB2. I need split the its values using "_" and get the third token in DB2. Then convert it into integer.
Person_Info
----------------
Person_BILL_1234_1511011900
Person_BOB_88888
Person_MARIOSAN_10_1511011900
The output should be:
1234
88888
10
I have checked this post How to split a string value based on a delimiter in DB2. It doesn't really solve this particular case.
Have also checked this post Split a VARCHAR in DB2 to retrieve a value inside, but it requires creating an stored procedure. I can't just create a stored proc in the production environment for some utility function.
Currently, I have tried:
Select INTEGER(
SUBSTR(
Person_Info, LOCATE('_', Person_Info, 10) + 1, 2
)
) from PersonTable
But it only works for "Person_MARIOSAN_10_1511011900".
So is there any solution to achieve this without creating any stored procedure? Especially if the solution is not bound to any hard coded values like 10 or 2 so that it will work in all the three examples I provided.