SQL Server中的单引号和双引号

时间:2022-09-15 13:41:30

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

1 个解决方案

#1


4  

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

因此,单引号应该是偶数我们得到的错误如下:字符串后的未闭合引号') - 错误

#1


4  

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

因此,单引号应该是偶数我们得到的错误如下:字符串后的未闭合引号') - 错误