1=1 永真, 1<>1 永假。
1<>1 的用處: 用于只取結構不取數據的場合
例如:
create table table_ly_temp tablespace ly_temp as
select * from table_ly where 1<>1
1
2
建成一個與table_ly 結構相同的表table_ly_temp ,但是不要table_ly 里的數據。(除了表結構,其它結構也同理)
1=1的用處: 用于動態SQL
在組合查詢條件時候多用:
String sql="select * from user where 1=1 ";
if(username!=null) sql=sql+ " and username=’"+username+"’";
if(password!=null) sql=sql+ " and password=’"+password+"’";
1
2
3
4
5
這樣方便很多,及時username,password兩者都為空都可以查詢
永遠為真 相當于沒有限制名稱條件。但是如果沒有1=1的條件,
select * from user where 會報錯
標簽:username,sql,oracle,table,password,where,ly
來源: https://blog.csdn.net/qq_39482010/article/details/89887876