The Messenger of Allah ﷺ said, "Whoever takes an oath and then sees that something else is better than it, let him make expiation for his oath and do what is better."
حدثنا أبو سلمة الخزاعي قال أخبرنا مالك عن سهيل بن أبي صالح عن أبيه
أن رسول الله ﷺ قال من حلف على يمين فرأى غيرها خيرا منها فليكفر عن يمينه وليفعل الذي هو خير
Suyuti related it with this wording, "Whoever swears an oath and then sees something better than it, let him do what is better and make atonement for his oath." Muslim and Tirmidhi related it from Abu Hurairah, and Suyuti marked it in Jami Saghir as sahih.