使用hibernate 框架时候,利用hql插入对象到数据库如:
User
private int uid;
private String uname;
如果我们不给uname 赋值,也就说只有uid有值,uname是空值,hibernate处理空值,在数据库是一对单引号,但是我们往往要组合查询时候,就是要查uname=‘’,这时候oracle和sqlserver的处理方式截然不同,
oracle 处理是(HQL) :select * from User u where u.uname is null ,当然u.uname=''肯定查不出来任何数据
恰恰相反:
sqlserver:select * from User u where u.uname =‘’
我们模拟的是利用hibernate插入数据库的方式,所有数据库中一定是单引号,如果是在PL/sql或者查询分析器中,这样
Sqlserver:
create table t( tid int primary key, tname varchar ); insert into t(tid) values(1); insert into t(tid) values(2); insert into t values(3,''); insert into t values(4,''); select * from t where tname is null; select * from t where tname = '';
结果:tid tname
1 NULL
2 NULL
tid tname
3
4
Oracle:
CREATE TABLE t( tid NUMBER PRIMARY KEY, tname VARCHAR2(20) ); INSERT INTO t (tid)VALUES(1); INSERT INTO t (tid)VALUES(2); INSERT INTO t VALUES(3,''); INSERT INTO t VALUES(4,''); COMMIT; SELECT * FROM t WHERE tname IS NULL; SELECT * FROM t WHERE tname ='';
结果:tid tname
1
2
3
4
tid tname
在处理空值时一定要小心,备忘