自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Oracle數(shù)據(jù)庫中null的具體使用方案

數(shù)據(jù)庫 Oracle
以下的文章主要介紹的是Oracle數(shù)據(jù)庫中null的具體使用方案的詳細(xì)解析,以下的文章就是Oracle數(shù)據(jù)庫中null的具體使用方案。

你是否對(duì)Oracle數(shù)據(jù)庫中null的實(shí)際操作感到十分頭疼?如果是這樣子的話,以下的文章將會(huì)給你相應(yīng)的解決方案,以下的文章主要是介紹Oracle數(shù)據(jù)庫中null的具體使用的方案,以下就是相關(guān)內(nèi)容的具體描述。

問:什么是NULL?

答:在我們不知道具體有什么數(shù)據(jù)的時(shí)候,也即未知,可以用NULL,

我們稱它為空,Oracle數(shù)據(jù)庫中,含有空值的表列長(zhǎng)度為零。

Oracle允許任何一種數(shù)據(jù)類型的字段為空,除了以下兩種情況:

1、主鍵字段(primary key),

2、定義時(shí)已經(jīng)加了NOT NULL限制條件的字段

說明:

1、等價(jià)于沒有任何值、是未知數(shù)。

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值總是排在***。

使用方法:

  1. SQL> select 1 from dual where nullnull=null; 

沒有查到記錄

  1. SQL> select 1 from dual where null=''

沒有查到記錄

  1. 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é)果仍為空。

  1. SQL> select 1+null from dual;  
  2. SQL> select 1-null from dual;  
  3. SQL> select 1*null from dual;  
  4. 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) ——月銷售金額

  1. create table sale (month char(6),sell number);  
  2. insert into sale values('200001',1000);  
  3. insert into sale values('200002',1100);  
  4. insert into sale values('200003',1200);  
  5. insert into sale values('200004',1300);  
  6. insert into sale values('200005',1400);  
  7. insert into sale values('200006',1500);  
  8. insert into sale values('200007',1600);  
  9. insert into sale values('200101',1100);  
  10. insert into sale values('200202',1200);  
  11. insert into sale values('200301',1300);  
  12. insert into sale values('200008',1000);  
  13. insert into sale(month) values('200009'); 

注意:這條記錄的sell值為空

  1. commit; 

 

共輸入12條記錄

 

  1. SQL> select * from sale where sell like '%';  
  2. MONTH SELL  
  3. ------ ---------  
  4. 200001 1000  
  5. 200002 1100  
  6. 200003 1200  
  7. 200004 1300  
  8. 200005 1400  
  9. 200006 1500  
  10. 200007 1600  
  11. 200101 1100  
  12. 200202 1200  
  13. 200301 1300  
  14. 200008 1000 

 

查詢到11記錄。

結(jié)果說明:

查詢結(jié)果說明此SQL語句查詢不出列值為NULL的字段

此時(shí)需對(duì)字段為NULL的情況另外處理。

 

  1. SQL> select * from sale where sell like '%' or sell is null;  
  2. SQL> select * from sale where nvl(sell,0) like '%';  
  3. MONTH SELL  
  4. ------ ---------  
  5. 200001 1000  
  6. 200002 1100  
  7. 200003 1200  
  8. 200004 1300  
  9. 200005 1400  
  10. 200006 1500  
  11. 200007 1600  
  12. 200101 1100  
  13. 200202 1200  
  14. 200301 1300  
  15. 200008 1000  
  16. 200009 

 

查詢到12記錄。

Oracle數(shù)據(jù)庫的空值就是這么的用法,我們***熟悉它的約定,以防查出的結(jié)果不正確。

【編輯推薦】

  1. 支付寶如何用Oracle 11g創(chuàng)建新一代數(shù)據(jù)的分析
  2. Oracle企業(yè)的績(jī)效管理統(tǒng)升級(jí)版簡(jiǎn)介
  3. Oracle企業(yè)管理器11g獲合作伙伴青睞的原因
  4. Oracle字符集中的一些問題總結(jié)
  5. Oracle修改相關(guān)字段的幾種常用方法
     
責(zé)任編輯:佚名 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-04-26 08:51:44

Oracle數(shù)據(jù)庫

2010-04-19 12:16:53

Oracle數(shù)據(jù)庫

2010-04-14 15:58:17

Oracle程序開發(fā)

2010-04-22 17:06:24

Oracle數(shù)據(jù)庫

2010-03-31 19:34:03

Oracle數(shù)據(jù)庫

2009-05-13 10:28:30

OracleDUAL數(shù)據(jù)庫

2011-05-26 14:31:57

Oracle數(shù)據(jù)庫

2011-08-12 12:26:16

Oracle數(shù)據(jù)庫TNSListener

2010-04-30 16:19:08

Oracle數(shù)據(jù)庫

2009-07-02 00:00:00

OOPOracle

2009-09-04 09:54:59

數(shù)據(jù)庫名

2010-04-22 15:26:53

Oracle進(jìn)程

2011-05-26 13:36:40

Oracle數(shù)據(jù)庫時(shí)間處理

2010-07-22 11:17:52

SQL Server數(shù)

2011-08-12 12:34:27

Oracle數(shù)據(jù)庫consistent

2010-02-01 10:10:41

Oracle數(shù)據(jù)庫優(yōu)化

2011-08-11 16:55:34

Oracle數(shù)據(jù)庫AWR

2011-05-24 14:13:20

Oracle數(shù)據(jù)庫

2010-04-22 11:58:00

Oracle數(shù)據(jù)庫

2010-04-13 17:22:31

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)