oracle 如何将带有'字符的简单字符串插入到oracle数据库中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13228609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:13:50  来源:igfitidea点击:

How to insert simple string with ' char into oracle database

databaseoracleinsert

提问by gabrjan

So my problem is that i need to insert company names into some database. It works fine but when i try to insert, for example Mc'Donalds it doesnt work because it finds end before the real end. So when i try that:

所以我的问题是我需要将公司名称插入到某个数据库中。它工作正常,但是当我尝试插入时,例如 Mc'Donalds,它不起作用,因为它在真正结束之前找到了结尾。所以当我尝试这样做时:

Inert into mydatabase (name, adress) values ('Mc'Donalds', 'somewhere') 

It crashes. Is there some char like \ to ignore it? Thank u!

它崩溃了。有没有像 \ 这样的字符来忽略它?感谢你!

回答by Dan Dascalescu

To escape reserved chars like ', you'll probably want to double the apostrophe character. See http://www.orafaq.com/faq/how_does_one_escape_special_characters_when_writing_sql_queries

要转义诸如 之类的保留字符',您可能需要将撇号字符加倍。见http://www.orafaq.com/faq/how_does_one_escape_special_characters_when_writing_sql_queries

回答by Rene

To be complete, you can also use the q function : q'[Mc'Donalds]'

为了完整起见,您还可以使用 q 函数: q'[Mc'Donalds]'

See also this blog entry: http://www.talkapex.com/2009/03/q-function-escape-single-quotes.html

另请参阅此博客条目:http: //www.talkapex.com/2009/03/q-function-escape-single-quotes.html