depends on what the code or fault was. there are some DTCs (fault codes) that will set right away, such as electrical voltage high or low. others require certain monitoring conditions to be met, and they may have to set on consecutive 'trips'. Once the code has set, it can automatically clear itself if either the monitors run again without the fault condition being detected or so many warmup cycles without the fault conditions present. depends on the fault.
That being said, you may be able to find a replacement o2 sensor flange and have an exhaust system shop remove the old one and weld in a new one. An example of the flange is here: https://www.amazon.com/gp/product/B01JYZ9Z1G/ref=ox_sc_act_title_1?smid=A2NMBIZOMZLC5C&psc=1
you would have to verify what the correct flange is for your vehicle, if you choose to go that route.
You can get a bung welded in or find an exhaust shop that has them.