我试图将一些文本数据插入到SQL Server 9中的表中。
文本中包含了一个引用。
我怎么逃脱呢?
我尝试使用两个单引号,但它给我带来了一些错误。
如。插入my_table值('hi, my name' s tim.');
我试图将一些文本数据插入到SQL Server 9中的表中。
文本中包含了一个引用。
我怎么逃脱呢?
我尝试使用两个单引号,但它给我带来了一些错误。
如。插入my_table值('hi, my name' s tim.');
当前回答
这应该是可行的:使用反斜杠和双引号
"UPDATE my_table SET row =\"hi, my name's tim.\";
其他回答
只要在要插入的任何东西之前插入一个'。它将像sqlServer中的转义字符
例子: 当你有场作为,我很好。 你可以: UPDATE my_table SET row ='I' m fine.';
Also another thing to be careful of is whether or not it is really stored as a classic ASCII ' (ASCII 27) or Unicode 2019 (which looks similar, but not the same). This isn't a big deal on inserts, but it can mean the world on selects and updates. If it's the unicode value then escaping the ' in a WHERE clause (e.g where blah = 'Workers''s Comp') will return like the value you are searching for isn't there if the ' in "Worker's Comp" is actually the unicode value.If your client application supports free-key, as well as copy and paste based input, it could be Unicode in some rows, and ASCII in others! A simple way to confirm this is by doing some kind of open ended query that will bring back the value you are searching for, and then copy and paste that into notepad++ or some other unicode supporting editor. The differing appearance between the ascii value and the unicode one should be obvious to the eyes, but if you lean towards the anal, it will show up as 27 (ascii) or 92 (unicode) in a hex editor.
如果用另一个单引号转义单引号对您不起作用(就像我最近的一个REPLACE()查询一样),您可以在查询之前使用SET QUOTED_IDENTIFIER OFF,然后在查询之后使用SET QUOTED_IDENTIFIER ON。
例如
SET QUOTED_IDENTIFIER OFF;
UPDATE TABLE SET NAME = REPLACE(NAME, "'S", "S");
SET QUOTED_IDENTIFIER ON;
-- set OFF then ON again
这应该是可行的:使用反斜杠和双引号
"UPDATE my_table SET row =\"hi, my name's tim.\";
STRING_ESCAPE函数可以在新版本的SQL Server上使用