Oracle SQL培训笔记[开发人员][二]

Oracle SQL培训笔记[开发人员][二]

三 null的那些事

  1. 在order 中,简单把null认为是最大
  2. 与null的运算,返回null
    SQL >   select   1   +   null   from  dual;

        
    1 + NULL
    -- --------
  3. 与null的字符串合并,忽略null
    SQL >   select   ' Hi ' || null   from  dual;

    ' HI ' || NULL
    -- --------
    Hi
  4. Null的查询为is null
  5. Count(field),不包括null
  6. 如果索引条目全为null,则索引不记录null
  7. In/not in与null
  8. Exists/not exists与null
    SQL >   select   *   from  t1;

    A          B
    -- -------- ----------
    1            1
    2           
    3           

    SQL
    >   select   *   from  t2;

    A          B
    -- -------- ----------
    1            1
    2           

    SQL
    >   select   *   from  t1  where  b  in  ( select  B  from  t2);

    A          B
    -- -------- ----------
    1            1

    SQL
    >   select   *   from  t1  where  b  not   in  ( select  B  from  t2);

    A          B
    -- -------- ----------

    SQL
    >   select   *   from  t1  where   exists  ( select   *   from  t2  where  t2.b  =  t1.b);

    A          B
    -- -------- ----------
    1            1

    SQL
    >   select   *   from  t1  where   not   exists  ( select   *   from  t2  where  t2.b  =  t1.b);

    A          B
    -- -------- ----------
    3           
    2           

    exists主要用于片面的,有满足一个条件的即可,  所以速度快很多.    in   主要用于具体的集合操作,   有多少满足条件.

你可能感兴趣的:(Oracle SQL培训笔记[开发人员][二])