Hi Marc, thank you so much. Actually I had to edit my question. My aim is to get the 5th field value from the last OBX segment in my HL7 message. Because I can have varying number of OBX segments but I know that the value I want is in the last OBX segment. 

So I thought if I could get the number of segments in a message, and then index that to get the last segment I could get the value I want.

Is there a better way to do that?

Sorry for the confusion. Appreciate your help

This was solved by writing a new function with the PrepareW command. I had the mySQL 8.0 Unicode driver installed. 

I cannot understand why I had to write a new function but it works. Following are the checks to consider (that I made):

1. Check the quotes against the values that you enter

2. Test with PrepareW statements

3. Increase the max_allocated_packet from 4M to 16M [in the more recent versions of mySQL it is default to 512M]

Regards,

Eric