If you have an erection that lasts over 4 hours, hurts, and doesn't result from being turned on, you could have a rare condition called priapism. It needs treatment fast.
Some erectile dysfunction (ED) drugs can cause it. But priapism can also result from injuries, medications, diseases, drug use, and even spider bites. A cold shower or ice packs can help. Light exercise like climbing stairs can help draw blood away from your penis into the rest of your body. It's important to see a doctor quickly, though. Untreated, priapism can cause scarring and erection problems that don’t go away.