There is oxygen in space. BUT, the oxygen is spread out that virtually you cannot make use it as a source of oxygen for your body. The Earth has gravity, that pulls together oxygen near each other.
So why Earth have oxygen but not any other planets? Well, all planets got some oxygen but not as much to sustain life. Earth started this way. A long long time ago, there was virtually no oxygen in the planet.
What happened is events such as volcano eruption, frequent collisions with other “space bodies”, hitting of comets and asteroids on Earth causes changes on the planet. And emergence of life happened with chemical reactions of simple organic compounds that lead to DNA and amino acids, that create life forms.
These life forms are in fact prokaryotes (or bacteria) and they are able to synthesise photosynthesis, which they release oxygen as their waste products. So there, when these bacteria begin to grow and multiply, you improve the percentage of O2 on Earth!
There are two important questions here: one is how much oxygen is there, and the other is how much oxygen gas (O_2) is there?
To start with, there’s not much of anything in space. Space is just huge areas of almost complete emptiness, punctuated by very small bits of very dense stuff. When the universe was first born, all the matter was spread out evenly. But as the universe expanded, this matter started to bunch together in clumps of different types and sizes. The biggest clumps we know of at the moment are galaxy clusters, which are made up of galaxies, which are clusters of stars (and asteroids and comets, etc), which sometimes have planets circling around them and these sometimes have moons, etc, etc. And because of gravity, these planets hold a blanket of other stuff around them – the atmosphere.
So what are the planets made out of? Well, one thing that has a strong influence on this is what the conditions were like when the planet formed in the first place – that is, what stuff was around when it started to clump together. Interestingly, there is also a lot of oxygen on Venus and Mars, which is perhaps not surprising, since they are the closest planets to Earth and probably formed in similar conditions. In their cases, however, most of the oxygen is there in the form of carbon dioxide.
As Allan pointed out, the biggest difference on Earth is that this carbon dioxide gets converted to oxygen gas (and some other stuff, including energy) via photosynthesis. Did you know that something like 70% of the Earth’s oxygen is produced by marine algae (mostly phytoplankton), most of which is too small to even see? It’s kind of weird to think that we’re only able to survive on this planet because of algae!
Oxygen is the third most abundant element in space but it is only present on Earth in such high concentrations (21% of our atmosphere). This is because of LIFE! Specifically tiny organisms called cyanobacteria or blue-green algae. Then once there was some oxygen, more animals producing oxygen evolved and the more animals, the more oxygen there was!
Oxygen was first produced on earth about 2.7 billion years ago but it wasn’t a permanent substantial part of our atmosphere until 2.45 billion years ago when life producing oxygen came alive! Scientists think that the Great Oxidation Event occurred because of a sudden lack of nickel which resulted in the kill-off of many methane-producing organisms that dominated the Earth before. This then left room for algae and other life forms that release oxygen during photosynthesis to grow and take over increasing the oxygen content of our atmosphere.