1

I'm working with 2 sets of data that were merged together, but they're inconsistent in their format. Some are 10 characters, all numbers. Others may have a separator : at position 4. I need to substring the first 4 characters. But if the 4th character is a : substring only the first 3 characters.

Does mysql have an IF functionality to determine the number of characters to substring based on the character in position 4?

select substring(id, 1 , 3/4) from table1
4

1 に答える 1