DB2 中between and 的边界

今天做测试时用到了between and .想到了边界问题。所以在DB2数据库中进行了一个小测试。各个数据可可能有所不同。

1) 首先我们创建测试所需要的表并插入数据

db2 => create table a(a1 int not null,a2 varchar(20))
db2 => insert into a values(1,'a'),(2,'b'),(3,'c'),(4,'d')

2)查看数据是否成功插入

db2 => select * from a


A1          A2                  
----------- --------------------
          1 a                   
          2 b                   
          3 c                   
          4 d                   


  4 record(s) selected.

3)进行between and 边界问题的的测试

db2 => select a1 from a where a1 between 1 and 4


A1         
-----------
          1
          2
          3
          4


  4 record(s) selected.

由此可以证明在DB2中between and 中是包含边界的。

4)进行not between and 边界问题的的测试

db2 => select a1 from a where a1 not between 0 and 4

A1         
-----------


  0 record(s) selected.

由此可以证明在DB2中not between and 中是不包含边界的。

db2 => select a1 from a where a1 not between 4 and 0


A1         
-----------
          1
          2
          3
          4


  4 record(s) selected.

好奇怪哦。又有边界了。。。?

db2 => select a1 from a where a1 not between 4 and null


A1         
-----------
          1
          2
          3


  3 record(s) selected.


你可能感兴趣的:(DB2)