There are three types of irony: dramatic, verbal, and situational.
Dramatic irony occurs when the audience knows something that the characters don't. This often occurs in a simplistic way in thrillers or horror movies when the audience knows that the killer or monster is lurking nearby, but the characters don't. The descrepency between what the audience knows and the characters know creates tension and suspense.
In Oedipus Rex the dramatic irony is much more complex. We, the audience, know that Oedipus is the king's killer and his own mother's husband. Since we know this, his efforts to find the king's killer creates a strong sense of "doom" about Oedipus on the part of the audience. As he gets closer and closer to the truth, we know that he is getting closer and closer to knowledge that will destroy him.
Creating the dramatically ironic situation requires a lot of skill on the part of the writer. When it is done effectively, it forces the audience to focus on the character's development, rather than on superficial plot twists. It's a great way for a writer to delve into the psychological makeup of his character.