Causes may be lying in esophagus,stomach or duodenum like bleeding ulcers,varices,
Mallory-
Weiss syndrome (esophageal tear),inflammation of any of the three, irritation or erosion of the lining of the esophagus or stomach, vascular malfunctions of the gastrointestinal tract and tumors of the stomach or esophagus.
Sometimes,it may be due to vomiting of ingested blood after hemorrhage in the oral cavity, nose or throat.