compare_packages_to_snapshot query fixes

First commit addresses an Oracle error that might show up depending on data.

Second commit should speed up execution considerably. At the best of my knowledge this should not alter behavior, please highlight errors if you spot any.