NULL 使用詳解
- 軟體環境:
- 1、Windows NT4.0+ORACLE 8.0.4
2、ORACLE安裝路徑為:C:ORANT
- 含義解釋:
- 問:什麼是NULL?
答:在我們不知道具體有什麼資料的時候,也即未知,可以用NULL,我們稱它為空,ORACLE中,含有空值的表列長度為零。
ORACLE允許任何一種資料型別的欄位為空,除了以下兩種情況:
1、主鍵欄位(primary key),
2、定義時已經加了NOT NULL限制條件的欄位
說明:
1、等價於沒有任何值、是未知數。
2、NULL與0、空字串、空格都不同。
3、對空值做加、減、乘、除等運算操作,結果仍為空。
4、NULL的處理使用NVL函式。
5、比較時使用關鍵字用“is null”和“is not null”。
6、空值不能被索引,所以查詢時有些符合條件的資料可能查不出來,count(*)中,用nvl(列名,0)處理後再查。
7、排序時比其他資料都大(索引預設是降序排列,小→大),所以NULL值總是排在最後。
- 使用方法:
SQL> select 1 from dual where null=null; 沒有查到記錄 SQL> select 1 from dual where null=''; 沒有查到記錄 SQL> select 1 from dual where ''=''; 沒有查到記錄 SQL> select 1 from dual where null is null; 1 --------- 1 SQL> select 1 from dual where nvl(null,0)=nvl(null,0); 1 --------- 1 對空值做加、減、乘、除等運算操作,結果仍為空。 SQL> select 1+null from dual; SQL> select 1-null from dual; SQL> select 1*null from dual; SQL> select 1/null from dual; 查詢到一個記錄. 注:這個記錄就是SQL語句中的那個null 設定某些列為空值 update table1 set 列1=NULL where 列1 is not null; 現有一個商品銷售表sale,表結構為: month char(6) --月份 sell number(10,2) --月銷售金額 create table sale (month char(6),sell number); insert into sale values('200001',1000); insert into sale values('200002',1100); insert into sale values('200003',1200); insert into sale values('200004',1300); insert into sale values('200005',1400); insert into sale values('200006',1500); insert into sale values('200007',1600); insert into sale values('200101',1100); insert into sale values('200202',1200); insert into sale values('200301',1300); insert into sale values('200008',1000); insert into sale(month) values('200009');(注意:這條記錄的sell值為空) commit; 共輸入12條記錄 SQL> select * from sale where sell like '%'; MONTH SELL ------ --------- 200001 1000 200002 1100 200003 1200 200004 1300 200005 1400 200006 1500 200007 1600 200101 1100 200202 1200 200301 1300 200008 1000 查詢到11記錄. 結果說明: 查詢結果說明此SQL語句查詢不出列值為NULL的欄位 此時需對欄位為NULL的情況另外處理。 SQL> select * from sale where sell like '%' or sell is null; SQL> select * from sale where nvl(sell,0) like '%'; MONTH SELL ------ --------- 200001 1000 200002 1100 200003 1200 200004 1300 200005 1400 200006 1500 200007 1600 200101 1100 200202 1200 200301 1300 200008 1000 200009 查詢到12記錄. Oracle的空值就是這麼的用法,我們最好熟悉它的約定,以防查出的結果不正確。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-84271/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 詳解Object.create(null)ObjectNull
- 深入詳解SQL中的NullSQLNull
- shell指令碼中/dev/null 2>&1詳解指令碼devNull
- Python中none和null的區別詳解!PythonNoneNull
- 【開發篇sql】 條件和表示式(三) Null詳解SQLNull
- 為什麼索引無法使用is null和is not null索引Null
- Jpa使用詳解
- mitmproxy使用詳解MIT
- Thymeleaf使用詳解
- mydumper使用詳解
- babel使用詳解Babel
- git使用詳解Git
- Mat使用詳解
- Proxy使用詳解
- nvm 使用詳解
- CSSModules使用詳解CSSSSM
- ctags使用詳解
- AutoLayout 使用詳解
- umask使用詳解
- OkHttp使用詳解HTTP
- Okhttp 使用詳解HTTP
- Inception使用詳解
- UITableView使用詳解UIView
- ViewFlipper使用詳解View
- ASIHttpRequest使用詳解HTTP
- at命令使用詳解
- opencv遇到NULL pointer(NULL array pointer is passed) 解決方案OpenCVNull
- ((NULL) null).printNULL();((NULL) null).printnull();Null
- NULL列時,如何使得IS NULL或者IS NOT NULL可以使用索引來提高查詢效率Null索引
- Supervisor使用詳解
- React Hooks 使用詳解ReactHook
- CMAKE的使用詳解
- Go Modules 詳解使用Go
- MFC——SkinMagic使用詳解
- Logstash使用詳解
- sed指令使用詳解
- Mybatis的使用詳解MyBatis
- Postman 使用教程詳解Postman