• 引见Oracle中null的应用方法。


    51 前导发端:网海拾贝




    问:什么是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的空值便是这么的用法,我们最好熟悉它的商定,以防查出的效果不准确




    版权声明: 原创作品,允许转载,转载时请务必以超链接体式格局标明文章 原始因由 、作者信息和本声明。不然将追查法律责任。

  • 相关阅读:
    【leetcode】1215.Stepping Numbers
    【leetcode】1214.Two Sum BSTs
    【leetcode】1213.Intersection of Three Sorted Arrays
    【leetcode】1210. Minimum Moves to Reach Target with Rotations
    【leetcode】1209. Remove All Adjacent Duplicates in String II
    【leetcode】1208. Get Equal Substrings Within Budget
    【leetcode】1207. Unique Number of Occurrences
    【leetcode】689. Maximum Sum of 3 Non-Overlapping Subarrays
    【leetcode】LCP 3. Programmable Robot
    【leetcode】LCP 1. Guess Numbers
  • 原文地址:https://www.cnblogs.com/zgqjymx/p/1976298.html
Copyright © 2020-2023  润新知