Home  >  Article  >  Database  >  oracle sql 语句中where条件中 1=1 是什么意思

oracle sql 语句中where条件中 1=1 是什么意思

WBOY
WBOYOriginal
2016-06-07 15:21:173308browse

下面整理于网络: oracle sql 语句中where条件中 1=1 是什么意思 1=1 是永恒成立的,意思无条件的,也就是说在SQL语句里有没有这个1=1都可以。 这个1=1常用于应用程序根据用户选择项的不同拼凑where条件时用的。 如:web界面查询用户的信息,where默认为1=1

下面整理于网络:

oracle sql 语句中where条件中 1=1 是什么意思

1=1 是永恒成立的,意思无条件的,也就是说在SQL语句里有没有这个1=1都可以。
这个1=1常用于应用程序根据用户选择项的不同拼凑where条件时用的。
如:web界面查询用户的信息,where默认为1=1,这样用户即使不选择任何条件,sql查询也不会出错。如果用户选择了姓名,那么where变成了where 1=1 and 姓名='用户输入的姓名',如果还选择了其他的条件,就不断在where 条件后追加 and语句就行了。如果不用1=1的话,每加一个条件,都要判断前面有没有where 条件,如果没有就写where ...,有就写and语句,因此此时用1=1可以简化了应用程序的复杂度

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn