Both Hamlet in William Shakespeare's play Hamlet and Oedipus in Sophocles' Oedipus Rex act as detectives. In both plays, we discover that before the action of the play proper starts, a king has been murdered. It is up to Oedipus and Hamlet to discover the identity of the murderers and to bring the murderers to justice. Both characters have the help of quasi-supernatural forces. Oedipus consults the prophet Tiresias as well as auguries (although he does not take their results sufficiently seriously) and Hamlet is given information by his father's ghost. Both characters go through extensive research and analysis, analyzing different types of evidence and conversing with a variety of possible witnesses.
The main differences are the identities of the murderers and the point in the play where we discover them. Hamlet's father's ghost reveals that Claudius, Hamlet's uncle, was the murderer near the beginning of the play, but Hamlet does spend most of the play trying to confirm this before eventually killing Claudius in the final scene. Oedipus only gradually realizes that he himself is the murderer he seeks, and although he does not commit suicide, he does blind and exile himself.