如何在SQL文件中转义引号?

时间:2016-06-17 15:13:46

标签: sql

我有一个很大的SQL文件,包含这样的行

(NULL, "190", "1986-07-23", "Kyoko's Gift ! "What , You Mean it's For Me?"", "Godai gets depressed over the rain, remembering that some of the worst events of his life have occured on rainy days. Kozue visits Maison Ikkoku and her skirt gets stained so she and Kyoko have snacks together while they wait for the skirt to dry. Kozue asks about Godai and learns that Kyoko is a widow. Kyoko remembers trying to flirt with Soichiro when she was in high school . After Kozue leaves, Godai runs into Kyoko, and she invites him to share an umbrella with her as they head home.", "0", "25", "18", "1"),

问题是该行的一部分有双引号:

,"Kyoko's Gift ! "What , You Mean it's For Me?"",

我总是得到一个错误,问题是有很多像这样的行,是否有一个很好的方法来逃避所有必要的引用以使其正常工作?

2 个答案:

答案 0 :(得分:2)

我假设你正在使用SQL Server,试试这个:

'Kyoko''s Gift ! What, You Mean it''s For Me?' 

答案 1 :(得分:0)

如果您有大量需要转义引号的查询,则需要在SSMS或文本编辑器中使用“查找/替换”来使用正确转义的引号替换引号。

首先使用双引号Select替换单引号'。 然后用单引号''替换双引号"

最后,你应该在字符串周围加上单引号,如下所示: ' 你的撇号应该被逃脱,如下: 'Foo Bar'