假如有一个字段 name    当name 不为空的时候显示 admin  用哪个函数  

解决方案 »

  1.   

    nvl(name,'无') 是为空的时候显示  那反之不为空呢
      

  2.   

    为空的时候,显示admin吧,不为空时,显示原来值
    nvl(name,'admin’)
      

  3.   

    写反了
    decode(name,null,为空时需要显示的值,'admin')
      

  4.   


    case when name is not null then 'admin'
      

  5.   

    nvl2(name, 'admin', '為null時,你想要的值')
      

  6.   

    与空值相关的函数:    NVL 函数       格式:NVL(表达式1,表达式2)       作用:测试表达式的值,如果表达式1为空,则返回表达式2的值;不为空,返回表达式1的值。     NVL2   函数       格式:NVL2(表达式1,表达式2,表达式3)       作用:测试表达式的值,表达式1不为空,返回表达式2的值,如果为空,则返回表达式3的值。      NULLIF  相等为空       格式:NULLIF (表达式1,表达式2)       作用:比较表达式1和表达式2的值,如果两个相等则返回为空,否则返回表达式1的值。     COALESCE    找非空       格式:COALESCE (表达式1,表达式2,表达式3,...,表达式n)       作用:返回第一个不为空的值,如果所有的都为空,则返回NULL。更多请参考:http://blog.csdn.net/robinson_0612/archive/2010/04/15/5487668.aspx
      

  7.   

    Purpose
    NVL lets you replace a null (blank) with a string in the results of a query. 
    If expr1 is null, then NVL returns expr2. If expr1 is not null, then NVL returns expr1. The arguments expr1 and expr2 can have any datatype. 
    If their datatypes are different, then Oracle converts expr2 to the datatype of expr1 before comparing them.The datatype of the return value is always the same as the datatype of expr1, unless expr1 is character data, in which case the return value's datatype is VARCHAR2 and is in the character set of expr1.Examples
    The following example returns a list of employee names and commissions, substituting "Not Applicable" if the employee receives no commission:SELECT last_name, NVL(TO_CHAR(commission_pct), 'Not Applicable')
       "COMMISSION" FROM employees
       WHERE last_name LIKE 'B%'
       ORDER BY last_name;
     
    LAST_NAME                 COMMISSION
    ------------------------- ----------------------------------------
    Baer                      Not Applicable
    Baida                     Not Applicable
    Banda                     .1
    Bates                     .15
    Bell                      Not Applicable
    Bernstein                 .25
    Bissot                    Not Applicable
    Bloom                     .2
    Bull                      Not Applicable
      

  8.   

    SELECT last_name, NVL(TO_CHAR(commission_pct), 'Not Applicable')
       "COMMISSION" FROM employees
       WHERE last_name LIKE 'B%'
       ORDER BY last_name;
     
    LAST_NAME                 COMMISSION
    ------------------------- ----------------------------------------
    Baer                      Not Applicable
    Baida                     Not Applicable
    Banda                     .1
    Bates                     .15
    Bell                      Not Applicable
    Bernstein                 .25
    Bissot                    Not Applicable
    Bloom                     .2
    Bull                      Not Applicable
      

  9.   

    case , nvl , decode 都可以。