浅谈where 1=1

1、简单理解的话where 1=1 永真, where 1<>1 永假

2、1<>1 的用处:
    用于只取结构不取数据的场合
    例如:
    create table table_temp tablespace tbs_temp as
    select * from table_ori where 1<>1
    建成一个与table_ori 结构相同的表table_temp,但是不要table_ori 里的数据。(除了表结构,其它结构也同理)

3、1=1的用处
     用于动态SQL
     例如 lv_string := 'select tbl_name,tbl_desc from tbl_test where 1=1 '||l_condition;
     当用户选择了查询的名称'abc'时l_condition :='and tbl_name = ''abc'''';但是当用户没有

选择名称查询时l_condition就为空 这样 lv_string = 'select tbl_name,tbl_desc from tbl_test

where 1=1 ' ,运行也不会出错,相当于没有限制名称条件。但是如果没有1=1的条件,则lv_string =

'select tbl_name,tbl_desc from tbl_test where ';这样就会报错。

4、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+"'";

}

转:http://blog.csdn.net/fanyuna/article/details/5972437

最新文章

  1. url带#号,微信支付那些坑
  2. iOS开发UI篇—APP主流UI框架结构
  3. Unity游戏开发之“屏幕截图”
  4. HDU5088——Revenge of Nim II(高斯消元&amp;矩阵的秩)(BestCoder Round #16)
  5. YUV422蓝屏显示输出功能辅助调试
  6. [BZOJ 3282] Tree 【LCT】
  7. PHP~foreach遍历名单数组~有必要多次观看练习
  8. 用UseMiddleware扩展方法注册中间件类
  9. angualrJs清除定时器
  10. AUTOSAR - 标准文档下载
  11. 使用Visual Studio Code开发.NET Core看这篇就够了
  12. 【Consul】CONSUL调研
  13. linux 与 windows 挖门罗币总结
  14. [转帖]服务器操作系统应该选择 Debian/Ubuntu 还是 CentOS?
  15. 一个最简单的通过WireShark破解SSL加密网络数据包的方法
  16. 论文笔记——MobileNets(Efficient Convolutional Neural Networks for Mobile Vision Applications)
  17. u-boot 2016.05 添加自己的board 以及config.h
  18. 北京师范大学第十六届程序设计竞赛决赛 F 汤圆防漏理论
  19. mongoDB的权限管理
  20. ajax 请求 后台返回的文件流

热门文章

  1. 【转】 远程到服务器安装visualSVN server,出现Service &#39;VisualSVN Server&#39; failed to start的解决方法
  2. 在html中添加缩放meta
  3. 获取URL参数
  4. PLSQL_性能优化系列06_Oracle Soft Parse / Hard Parse软硬解析
  5. studio-引入外来包
  6. (转)zookeeper学习记录--附browser
  7. LPC1768之ISP
  8. JS定时执行,循环执行
  9. Java链式方法 连贯接口(fluent interface)
  10. git fetch和git pull(转载)