The Church does NOT forbid it. What you heard is wrong. What you must not do is swear a false oath.
CCC 2149 Oaths which misuse God’s name, though without the intention of blasphemy, show lack of respect for the Lord. The second commandment also forbids magical use of the divine name.
CCC 2150 The second commandment forbids false oaths. Taking an oath or swearing is to take God as witness to what one affirms. It is to invoke the divine truthfulness as a pledge of one’s own truthfulness. An oath engages the Lord’s name. “You shall fear the LORD your God; you shall serve him, and swear by his name.”
CCC 2154 Following St. Paul,** the tradition of the Church has understood Jesus’ words as not excluding oaths made for grave and right reasons (for example, in court).** “An oath, that is the invocation of the divine name as a witness to truth, cannot be taken unless in truth, in judgment, and in justice.”
CCC 2163** False oaths call on God to be witness to a lie.** Perjury is a grave offence against the Lord who is always faithful to his promises.