search
HomeDatabaseMysql TutorialOracle中null的使用详解

最好不查找NULL,或is not null ,is null,更不能比较null值问:什么是NULL?答:在我们不知道具体有什么数据的时候,也即未知,

最好不查找NULL,或is not null ,is null,更不能比较null值

问:什么是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)  --月份
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记录.
       
结果说明:
查询结果说明此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的空值就是这么的用法,我们最好熟悉它的约定,以防查出的结果不正确。

其他意见:

在 MS SQL Server 中,是存在的。
即WHERE field_1 IS NULL 和 filed_1 = '' 返回 2 种结果
'' 和 NULL 是2个东西。

在 Oracle 8.1.6   和 9.2 中,你存入 '' 后,数据库会自动存储为 NULL
此时只能使用 WHERE field_1 IS NULL
感觉好像 ORACLE 中没有 '' 或者说 '' 和 NULL 是一个东西。

可以这么理解:

如果需要区分数据类型的话,
空字符串''一定是NULL
空数字也是NULL
其他空数据类型也是NULL

如果不区分数据类型的话,
空字符串''就是NULL,NULL就是空字符串''

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
C程序用于找到一个数的最大质因子C程序用于找到一个数的最大质因子Aug 27, 2023 am 10:09 AM

PrimeFactor−Innumbertheory,theprimefactorsofapositiveintegeraretheprimenumbersthatdividethatintegerexactly.Theprocessoffindingthesenumbersiscalledintegerfactorization,orprimefactorization.Example−Primefactorsof288are:288=2x2x2x2x2

全球数字虚拟币交易平台排行榜前十(2025权威排名)全球数字虚拟币交易平台排行榜前十(2025权威排名)Mar 06, 2025 pm 04:36 PM

2025年全球数字虚拟币交易平台竞争激烈,本文根据交易量、安全性、用户体验等指标,权威发布2025年全球十大数字虚拟币交易平台排行榜。OKX凭借强大的技术实力和全球化运营策略居首,Binance以高流动性和低费用紧随其后。Gate.io、Coinbase、Kraken等平台凭借各自优势稳居前列。榜单涵盖Huobi、KuCoin、Bitfinex、Crypto.com和Gemini等交易平台,各有特色,但投资需谨慎。选择平台需考虑安全性、流动性、费用、用户体验、币种选择及监管合规性等因素,理性投资

币圈十大交易所2025年最新 数字货币app排行榜前十币圈十大交易所2025年最新 数字货币app排行榜前十Feb 27, 2025 pm 06:33 PM

虚拟货币十大交易平台排行榜(2025年最新): 币安:全球龙头,高流动性,监管受关注。 OKX:庞大用户基数,支持多种币种,提供杠杆交易。 Gate.io:资深交易所,多种法币支付方式,提供多种交易对和投资产品。 Bitget:衍生品交易所,高流动性,低费用。 火币:老牌交易所,支持多种币种和交易对。 Coinbase:美国知名交易所,受监管严格。 Phemex等等。

十大数字货币交易平台 数字货币交易平台top10榜单最新十大数字货币交易平台 数字货币交易平台top10榜单最新Mar 17, 2025 pm 05:57 PM

十大数字货币交易平台:1. OKX,2. Binance,3. Gate.io,4. Huobi Global,5. Kraken,6. Coinbase,7. KuCoin,8. Bitfinex,9. Crypto.com,10. Gemini,这些交易所各具特色,用户可根据安全性、费用、币种选择、用户界面和客户支持等因素选择适合自己的平台。

数字货币app十大交易平台 炒币正规平台app推荐数字货币app十大交易平台 炒币正规平台app推荐Mar 07, 2025 pm 06:51 PM

本文推荐十个数字货币交易App:1. OKX;2. Binance;3. Gate.io;4. Huobi Global;5. Kraken;6. Coinbase;7. KuCoin;8. Crypto.com;9. Bitfinex;10. Poloniex。选择平台需考虑安全性、流动性、交易费用、币种选择、用户界面、客服支持及法规合规性等因素,谨慎评估风险,切勿盲目跟风。

靠谱的数字货币平台有哪些 十大正规数字货币交易平台2025靠谱的数字货币平台有哪些 十大正规数字货币交易平台2025Mar 17, 2025 pm 05:45 PM

靠谱的数字货币平台包括:1. OKX,2. Binance,3. Gate.io,4. Huobi Global,5. Kraken,6. Coinbase,7. KuCoin,8. Bitfinex,9. Crypto.com,10. Gemini,这些交易所各具特色,用户可根据安全性、费用、币种选择、用户界面和客户支持等因素选择适合自己的平台。

十大数字货币app交易平台 top10虚拟货币app2025排行榜十大数字货币app交易平台 top10虚拟货币app2025排行榜Mar 13, 2025 pm 07:00 PM

十大虚拟币交易平台排名依次为:1. OKX;2. Binance;3. Gate.io;4. Huobi Global;5. Kraken;6. Coinbase;7. KuCoin;8. Crypto.com;9. Bitfinex;10. Gemini。 排名基于平台流动性、币种选择、安全性、用户体验、手续费及合规性等因素综合考量,但仅供参考,投资需谨慎,风险自担。

十大数字货币交易app排行榜top10推荐十大数字货币交易app排行榜top10推荐Feb 17, 2025 pm 03:18 PM

随着数字货币市场的繁荣,本文列出了十大数字货币交易 App 排行榜,以帮助投资者选择可靠且易用的平台。排行榜包括币安、Coinbase、Gemini、Kraken、FTX、Huobi、OKX、Bitfinex、Crypto.com 和 Gate.io。这些 App 提供了广泛的交易对、安全可靠的平台、低交易费用和高流动性等优势。投资者应根据安全、用户友好性、交易费用、流动性、支持的币种和客户服务等因素,选择最符合他们需求的 App。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment