The Prophet ﷺ said, "By Allah, if Allah wills, I do not swear an oath and then see something better than it without making expiation for my oath and doing what is better," or he said, "without doing what is better and making expiation for my oath."
حدثنا سليمان بن حرب حدثنا حماد حدثنا غيلان بن جرير
أن النبي ﷺ قال إني والله إن شاء الله لا أحلف على يمين فأرى غيرها خيرا منها إلا كفرت عن يميني وأتيت الذي هو خير أو قال إلا أتيت الذي هو خير وكفرت يميني
Bukhari, Oaths and Vows, chapter, "The saying of Allah Almighty, 'Allah will not hold you accountable for the thoughtless utterances in your oaths,'" no. 6623, and Muslim, Oaths, chapter, "Recommendation for one who swears an oath and then sees something better than it in..." no. 1649, from the hadith of Hammad bin Zayd, with the same chain.