In general if you have an ulcer, you should take your medications as prescribed as that is the best way to heal the ulcer.Taking medicines as you need usually will not allow that healing to occur. And because ulcers can be infection or can lead to more serious problems you need follow-up.
Sometimes people say "ulcer" when they have reflux
or dyspepsia. Intermittent symptoms can be treated as needed.