Well, you can, but not directly. Anyway, you need to go into the Rules.txt and make your settlers/engineers able to transform terrain into ocean. Then you build railroad in a square, and transform it into ocean. But don't ask me the benefits of this.
And before you ask, I have don't know how to make settlers/engineers able to make ocean.