where 1=1 表示永远为真!主要是为了便于动态连接后续条件 

在组合查询条件时候多用:

String sql="select * from user where 1=1 ";

if(username!=null) sql=sql+ " and username='"+username+"'";

if(password!=null) sql=sql+ " and password='"+password+"'";

这样方便很多,及时username,password两者都为空都可以查询

 

写程序时也会这么用,比如说:
select *from table where @IsNull(field1,strPrint("filed1=$",0))
如果field1等于空的,那where 后面就没有条件了,势必会报错,所以加上1=1

相关文章:

  • 2021-05-10
  • 2021-10-01
  • 2022-12-23
猜你喜欢
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案