使用结构:函数
decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值)spa
该函数的含义以下:翻译
IF 条件=值1 THEN
RETURN(翻译值1)
ELSIF 条件=值2 THEN
RETURN(翻译值2)
......
ELSIF 条件=值n THEN
RETURN(翻译值n)
ELSE
RETURN(缺省值)
END IFcode
例子:blog
①io
select *from users;select
select id, username, age, decode(sex,0,'男',1,'女') from users;im
②--子查询
select
sysuser.id,
sysuser.userid,
sysuser.username,
sysuser.groupid,
decode(sysuser.groupid,
'1',(select mc from userjd where sysuser.sysid=userjd.id),
'2',(select mc from userjd where sysuser.sysid=userjd.id),
'3',(select mc from useryy where sysuser.sysid=useryy.id),
'4',(select mc from usergys where sysuser.sysid=usergys.id)
) as mc
from sysuser;d3