sal number(10);select length(name) into sal from table1 where id =1;当name ='' or name is null 的时候 sal 中是null 还是0

解决方案 »

  1.   


    --这种问题一试便知
    scott@YPCOST> select length(comm),comm from emp;LENGTH(COMM)       COMM
    ------------ ----------
               3        900
               3        300
               3        500
               3        900
               4       1400
               3        900           1          0
               3        900           3        900
      

  2.   


    with tab as
    (
    select null id from dual
    )
    select length(id) len from tab
    -----------------------------------
    len
    ----
    null
      

  3.   

    with tab as
    (
    select '' id from dual
    )
    select length(id) len from tab
    -----------------------------------
    len
    ----
    null(空白用null来表示了)
      

  4.   

    由于NULL是一个未知的值,所以得到的长度也是未知的
    即结果同样为NULL
      

  5.   

    with tab as (select 'abc' as c1,'' as c2,null as c3 from dual)
    select Length(c1),length(c2),length(c3) from tab
    结果无论是‘’还是null length都为空
      

  6.   

    ORACLE 中 NULL 的意思是“未知”
    所以对于字段的操作,应该事先对该字段进行 NULL 判断
    IS NULL 
    只有在得到非 NULL 的结果时,再对其作其他操作
    所以应该从根本上避免对可能 NULL 的字段去判断长度