谁能告诉我IIF在Oracle和SQL Server中的语法(急)

谁能告诉我IIF在Oracle和SQL Server中的语法
---------------------------------------------------------------

情况1:
SQL Server:
select (case a1 when '0' then 'easy'
when '1' then 'normal'
when '2' then 'hard' end) level
from a;
Oracle:
select decode(a1,'0', 'easy', '1', 'normal', '2', 'hard') level from a;
情况2:
SQL Server:
select (case when a1 between 0 and 60 then 'no pass'
when a1 between 61 and 80 then 'normal'
when a1 between 81 and 100 then 'good' end) level
from a;
Oracle:
select decode(sign(a1-61),-1, 'no pass',decode(sign(a1-81),-1, 'normal', 'good') level from a;

备注:
decode的用法是decode(表达式,期待值1,转换值1, 期待值2,转换值2,……)
sign的用法是sign(表达式),如果表达式<0则函数返回-1,如果表达式=0则函数返回0,如果表达式>0则函数返回1.

---------------------------------------------------------------

我不知道iif,
可能你要decode函数的用法吧

decode(x,1,'a',2,'b',3,'c','z')
当x为1,表达式返回a
当x为2,表达式返回b
当x为3,表达式返回c
其余返回z

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus