I suggest you use the plugin Search Regex instead of doing MySQL queries, since it has the option to show you what would be changed before changing it. If you don’t know regular expressions, you might need to read up on that first.
And if you do have a way to distinguish between start and end <h5>, you can use a two step approach.