There are many examples of and instructions for giving oaths in the Bible, but the critics place them against these two NT verses (the latter of which is likely alluding to the former):
Matthew 5:34-37 "But I say unto you, swear not at all; neither by heaven . . . nor by the earth . . . . Neither shalt thou swear by thy head . . . . But let your communication be, Yea, yea; Nay, nay: for whatsoever is more than these cometh of evil."
James 5:12 ". . . swear not, neither by heaven, neither by the earth, neither by any other oath: but let your yea be yea; and your nay, nay; lest ye fall into condemnation."
Heb. 7:21 "The Lord sware and will not repent."
So are these simple "no oath" commands that contradict the rest of the Bible's oaths and instructions for them? And is God violating his own rule?
What is being condemned in the NT verses is not oath-taking per se, but flippant, casual oaths. The words "at all" in Matthew come from holos, which can mean simply, "not at all," but can also mean "commonly."
Let's look at ALL of the verses from Matthew:
Matt. 5:34-7 But I tell you, Do not swear at all: either by heaven, for it is God's throne; or by the earth, for it is his footstool; or by Jerusalem, for it is the city of the Great King. And do not swear by your head, for you cannot make even one hair white or black. Simply let your 'Yes' be 'Yes,' and your 'No,' 'No'; anything beyond this comes from the evil one.
Now, who makes a serious, solemn oath on heaven, the earth, a city, or their own head? The NT is condemning people who treat oaths with contempt by making them thoughtlessly.
Keener's commentary on Matthew (192ff) explains the historical context of these passages. All ancient societies viewed oath-taking as dangerous, since they essentially called upon a deity to execute vengeance if the oath was not fulfilled. A flippant or false oath was in a real sense a blasphemy, a casual misuse of the name of God.
Somewhat paralleling the words of Jesus, the Essenes seem to have avoided oaths altogether, other than their oath of initiation. The Greek philosopher Pythagoras and others similarly taught, "let one's word carry such conviction that one need not call deities to witness." In the context of Jesus' own day, there existed a "popular abuse" of oath-taking in which surrogate objects were introduced to swear by, so as not to profane the divine name -- things like the right hand, Jerusalem, God's throne, and the head. Jesus also addresses this practice in his directive not to swear on such objects, as some thought it easier to break an oath if they swore on something inanimate rather than God.
What we therefore have here is an example of Jesus not disagreeing with the OT about oaths, but rather moving beyond the OT into an even more demanding standard that focuses on motivation rather than action (in the same manner as the "adultery in the heart" directive).