How long does it take for the medicine to be effective according to the cause of stomach pain, if the pain is caused by indigestion, the medicine can be effective after a few hours, if it is a peptic ulcer, it can be effective in a day or so, if it is stomach pain caused by gastric cancer and other diseases, it needs to be surgically treated, and different medicines can be taken according to different conditions. 1. Dyspepsia: dyspepsia is usually caused by irregular diet, overeating, eating spicy and stimulating food, you can take mosapride, itopride and other drugs under the guidance of the doctor, and the stomach pain will be improved in a few hours after taking them. 2. Peptic ulcer: caused by some gastrointestinal diseases, you can take omeprazole enteric-coated capsules, pantoprazole sodium enteric-coated tablets, bismuth pectin and other medicines under the guidance of the doctor, and the effect will be seen in one day after taking them. 3. Gastric cancer: it needs to be treated by surgery, radiotherapy, chemotherapy and other therapies to prolong the survival period, and it is impossible to relieve it by medication. Pay attention to daily diet, prevent overeating, eat less spicy and stimulating food, pay attention to exercise and rest, keep optimism.