Oracle中的”值和null以及java中的null区别

关于三者的区别,我做了一个实验,下面是JUnit的代码片断:

public void testInsert(){
Connection conn = null;
try{
conn = dbPool.getConnection();
assertNotNull(conn);
// sql script
String sql;
sql = "INSERT INTO TEST (Note, Name) Values ('''''', '')";
//sql = "INSERT INTO TEST (Note, Name) Values ('Oracle NULL', NULL)";
//sql = "INSERT INTO TEST (Note, Name) Values ('Java null', " + null + ")";
//sql = "INSERT INTO TEST (Note, Name) Values ('Java null string', '" + null + "')";
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
} catch(Exception e){
fail(e.getMessage());
} finally{
if(conn != null)
try { conn.close();} catch (SQLException e) {}
}
}

依次执行上面代码中的四个sql语句,然后打开SQL*Plus,执行查询
select id from test where name is null;
结果:

Note Name
--------------------------------------------------------------------------------
''
Oracle NULL
Java null

执行
select id from test where name is not null;
结果:

Note Name
--------------------------------------------------------------------------------
Java null string null

发表评论

电子邮件地址不会被公开。 必填项已用*标注