您的位置:首页 > 数据库 > Oracle

oracle decode nvl nvl2 sign(即sin) 函数用法

2007-08-18 16:07 393 查看
select decode(p.xx,1,'no1',2,'no2') from person p
这样只能做等于,如果xx等于1就显示no1,等于2显示no2;

当我们需要做大于小于判断的时候就要借助sign函数了,select decode(sign(p.reportDate-p.finishDate),1,p.reportDate,0,p.reportDate,-1,'') from person p,如果reportDate减去finishDate是个正数则sign函数返回1,负数为-1,0为0, 

NVL(EXPR1,EXPR2)
若EXPR1是NULL,则返回EXPR2,否则返回EXPR1.
SELECT NAME,NVL(TO_CHAR(COMM),'NOT APPLICATION') FROM TABLE1;

Use   of   the   New   NVL2   Function    
  Most   of   us   are   familiar   with   the   NVL   function   which   checks   for   the   existence   of   NULL   values.   Oracle   provides   a   new   function   called   NVL2   which   checks   for   the   existence   of   NOT   NULL.   The   syntax   for   this   function   is   as   follows.
  NVL2(expr1,expr2,expr3);  
  If   expr1   is   not   null   then   the   function   will   return   expr2.   Otherwise,   the   function   will   return   expr3.   The   expr1   can   have   any   datatype   and   arguments   expr2   and   expr3   can   be   of   any   datatype   other   than   LONG.   The   datatype   of   the   return   value   is   that   of   expr2. 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息