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.