Ame*_*mee 1 sql sql-server sql-server-2008
我想知道使用引号时发生此错误的确切原因。
INSERT INTO table_check(name) VALUES('hello'hi') -- ERROR
INSERT INTO table_check(name) VALUES('hello''hi') -- RESULT:- hello'hi
INSERT INTO table_check(name) VALUES('hello'''hi') --ERROR
INSERT INTO table_check(name) VALUES('hello''''hi') --RESULT:- hello''hi
INSERT INTO table_check(name) VALUES('hello'''''hi') --ERROR
INSERT INTO table_check(name) VALUES('hello''''''hi') --RESULT:- hello'''hi
Run Code Online (Sandbox Code Playgroud)
单引号通过加倍来转义。因此,只要出现偶数个引号,我们就会得到结果。
要了解单引号的行为,请尝试运行以下代码:
Select '','''','''''','''''''',''''''''''
Run Code Online (Sandbox Code Playgroud)
所以,单引号应该是偶数,否则我们会得到类似的错误:在字符串 ') 之后出现未闭合的引号-- ERROR
| 归档时间: |
|
| 查看次数: |
2169 次 |
| 最近记录: |