set ansi_nulls 和set quoted_identifier的使用总结

简介:

set ansi_nulls on的用法

指定在与 Null 值一起使用等于 (=) 和不等于 (<>) 比较运算符时采用符合 ISO 标准的行为。

 SET ANSI_NULLS  ON 时,即使 column_name 中包含空值,使用 WHERE column_name = NULL  SELECT 语句仍返回零行。即使 column_name 中包含非空值,使用 WHERE column_name <> NULL  SELECT 语句仍会返回零行。

 SET ANSI_NULLS  OFF 时,等于 (=) 和不等于 (<>) 比较运算符不遵守 ISO 标准。使用 WHERE column_name = NULL  SELECT 语句返回 column_name 中包含空值的行。使用 WHERE column_name <> NULL  SELECT 语句返回列中包含非空值的行。

 

select * from qlei where sname is null

select * from qlei where sname is not null

结果如图:

set ansi_nulls on

select * from qlei where sname = null

select * from qlei where sname<>null

结果如图:

set ansi_nulls off

select * from qlei where sname = null

select * from qlei where sname<>null

结果如图:

6. SET QUOTED_IDENTIFIER的用法

 SET QUOTED_IDENTIFIER  ON 时,标识符可以由双引号分隔,而文字必须由单引号分隔。当 SET QUOTED_IDENTIFIER OFF 时,标识符不可加引号,且必须符合所有 Transact-SQL 标识符规则。在默认情况下,SET QUOTED_IDENTIFIER ON

set quoted_identifier on

select * into "user" from qlei--user为系统关键字如果直接使用会报错

select * from "user" where sno='990028'

select * from [user] where sno='990028'—-单引号变成双引号报错

结果如图:

 set quoted_identifier off

select * from user where sno='990028'--这样写报错

select * from [user] where sno='990028'

select * from [user] where sno="990028"

结果如图:



本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/380214,如需转载请自行联系原作者

 

相关文章
|
关系型数据库 MySQL Java
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually
4179 1
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually
When allowCredentials is true, allowedOrigins cannot contain the special value ___ since that cannot be set on the _Access-Contr
When allowCredentials is true, allowedOrigins cannot contain the special value ___ since that cannot be set on the _Access-Contr
335 1
|
SQL 关系型数据库 Oracle
set echo on/off,set term on/off,set feedback off,set heading off命令(转)
1.term命令:  当和SPOOL命令联合使用时,可以取消SQLPLUS输出,查询结果仅仅存在于假脱机文件中  set term on:查询结果既显示于假脱机文件中,又在SQLPLUS中显示;  set term off:查询结果仅仅显示于假脱机文件中。
1576 0