Difficult to say. Many people do not understand that diagnostic codes are not designed to tell you what device failed. After the dealer replaces an O2 sensor, he resets your check engine codes, which always makes the light go away. You have to drive it several miles for three or four start ups after the reset to ensure that the code is really gone. So in a sense, yes, it always works, because part of the procedure is to make the light shut off… at least temporarily.
The problem is, many emissions-related system failures will cause the O2 sensor to report that it’s data is out of range. A lot of people replace perfectly good O2 sensors, because reading the code does not tell you what component has failed. For instance, if you have a vacuum leak, your fuel-air mixture will run to rich or lean, and the O2 sensor will report out of range data.