sql server 数据库中经常与遇到插入各类带单引号 ’ 或是 双引号 ’ ’ 的数据,那么应该怎么插入呢?
正常情况下:
这样插入就不会有问题:
insert into table(description) values('Director Fee')
但是这样呢?
insert into table(description) values('Director's Fee')
数据库语法报错:
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near 'Fee'.
Msg 105, Level 15, State 1, Line 8
Unclosed quotation mark after the character string ''.
如何解决呢?
很简单,将单引号 ' 改为 '' 即可:
insert into table(description) values('Director''s Fee')
这样就可以了
但若是要插入的是 双引号 ' ' 呢?把 ' '改成 '''' 即可:
insert into table(description) values('Director''s Free ''Tina''')
结果就是:
Director's Free 'Tina'
insert into table(description) values('Director''s Free ''''Tina''''')
结果就是:
Director's Free “Tina”