Earth was a burning sphere millions of years ago. Water has remained in the stage of gas till earth got cooled below 212 degrees Fahrenheit. At that time, 3.8 billion years ago, the water condensed into the rain and it rained for centuries.
The water got drained into the great hollows of the Earth's surface and got filled into the basins. The Earth's gravitational power prevented the water from leaving the planet. The rainwater which filled the basins has become oceans. This is how oceans have formed.