简体   繁体   English

SQL Server中的单引号和双引号

[英]Single and double quotes in SQL Server

I want to know exact reason why this error occur playing with quotes. 我想知道为什么使用引号时会发生此错误。

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

Single Quotes are Escaped by Doubling Them up.So whenever even number of Quotes are present, then we get the Result. 将单引号加倍即可转义单引号。因此,只要出现偶数个引号,便可以得到结果。

To Know The Behavior of Single Quotes Try to Run This Below Code: 要知道单引号的行为,请尝试在以下代码下运行:

Select '','''','''''','''''''',''''''''''

So,Single Quotes Should be Even Number Else We get error like: Unclosed quotation mark after the character string ') -- ERROR 因此,单引号应为偶数,否则我们将收到类似以下错误:字符串')后的引号引起来 -错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM