zoukankan      html  css  js  c++  java
  • Null值操作

      1)NULL值写入的操作
       create table j010(
        id number(7),
        name varchar2(20),
        salary number(7,2));
       //插入时指定null
       insert into j010(id,name,salary)
        values(101,'scott',null);
       //不指定字段值默认为null
       insert into j010(id,name)
        values(102,'bob');
       //将字段值更新成null
       update j010 set name=null where id=101;
     
      2)null值做条件查询
       //查询salary为null值的记录
       select * from j010
       where salary is null;
       //查询name不为null值得记录
       select * from j010
       where name is not null;
      3)null值处理函数
       NVL(字段,值1):如果字段值为null,返回值1;
                    如果不为null,返回原字段值
      //如果salary字段值为null,返回0,再加上100
      select id,name,NVL(salary,0)+100
      from j010;
     
      //显示名字和工资,工资为null时显示0;
      //名字为null时显示'无名氏'
      select nvl(name,'无名氏'),nvl(salary,0)
      from j010;
     
      NVL2(字段,值1,值2):如果字段值为null返回值2;
                       如果字段值不为null返回值1
     
      //显示名字和工资,工资为null时显示'无薪'
      //如果不为null时显示'保密'
      select name,nvl2(salary,'保密','无薪')
      from j010;
     
    4)null值限定(非空约束)
       字段值不能为null,如果给null值报错。
     
       create table j011(
        id number(7) not null,
        name varchar2(20) not null
       );
     
      insert into j011(id,name) values(101,null);//错误
      insert into j011(id,name) values(null,1000);//错误
      insert into j011(id) values(102);//错误
     
    *2.NULL值操作
      NULL空值可以放在各个类型字段中。
      如果NUMBER类型字段值为NULL,表示无穷大。
      其他类型字段使用NULL表示没有值
  • 相关阅读:
    C++高精度乘法
    经典的7种排序算法 原理C++实现
    c++ STL
    二分查找c++
    洛谷P1111 修复公路
    01背包写法
    c++编码规范
    github教程
    windows10锁定屏幕聚焦图片导出
    week 6 Spring history and design philosophy
  • 原文地址:https://www.cnblogs.com/yunman/p/5497443.html
Copyright © 2011-2022 走看看