Oracle中decode函数

语法:

decode(value,if1,then1,if2,then2,if3,...,else)

表示:如果value等于if1,decode函数的结果返回then1,...,如果不等于任何一个if值,则返回else。

含义解释:

decode(条件,值1,翻译值1,值2,翻译值2,...,值n,翻译值n,缺省值)

相当于:

if 条件=值1 then

  return(翻译值1)

elsif 条件=值2 then

  return(翻译值2)

  ......

elsif

  return(缺省值)

end if;

使用技巧:

1、比较大小

select decode(sign(a-b),-1,a,b) from dual;       --取a、b中较小值

sign(n)函数,取n的符号,n大于0则返回1,n小于0则返回-1,n等于0则返回0.

你可能感兴趣的:(oracle)