Opioids, such as oxycodone, morphine, codeine, tramadol and fentanyl, are commonly prescribed to manage pain. You might be given a prescription when experiencing pain, or after surgery or an injury. But while opioids may relieve pain in the short term, they provide little to no lasting improvement in pain or function beyond a few weeks for people whose pain isn’t caused by cancer.