沒有給賦值,也沒有默認(rèn)值時(shí)為null
ORACLE允許任何一種數(shù)據(jù)類型的字段為空,除了以下兩種情況: 1、主鍵字段(primary key), 2、定義時(shí)已經(jīng)加了NOT NULL限制條件的字段
說明: 1、等價(jià)于沒有任何值、是未知數(shù)(未賦值,且沒有默認(rèn)值)。 2、NULL與0、空字符串、空格都不同。 3、對(duì)空值做加、減、乘、除等運(yùn)算操作,結(jié)果仍為空。 4、NULL的處理使用NVL函數(shù)。 5、比較時(shí)使用關(guān)鍵字用“is null”和“is not null”。 6、 空值不能被索引 ,所以查詢時(shí)有些符合條件的數(shù)據(jù)可能查不出來, count(*)中,用nvl(列名,0)處理后再查。 7、排序時(shí)比其他數(shù)據(jù)都大(索引默認(rèn)是降序排列,小→大), 所以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 對(duì)空值做加、減、乘、除等運(yùn)算操作,結(jié)果仍為空。 SQL> select 1+null from dual; SQL> select 1-null from dual; SQL> select 1*null from dual; SQL> select 1/null from dual; 查詢到一個(gè)記錄. 注:這個(gè)記錄就是SQL語句中的那個(gè)null設(shè)置某些列為空值 update table1 set 列1=NULL where 列1 is not null;現(xiàn)有一個(gè)商品銷售表sale,表結(jié)構(gòu)為: month char(6) --月份 sellnumber(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記錄. 結(jié)果說明: 查詢結(jié)果說明此SQL語句查詢不出列值為NULL的字段 此時(shí)需對(duì)字段為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記錄.
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
