使用结构:


decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值)

 

 

该函数的含义如下:


IF 条件=值1 THEN
    RETURN(翻译值1)
ELSIF 条件=值2 THEN
    RETURN(翻译值2)
    ......
ELSIF 条件=值n THEN
    RETURN(翻译值n)
ELSE
    RETURN(缺省值)
END IF

 

例子:

select *from users;

 

select id, username, age, decode(sex,0,'男',1,'女') from users;

 

 

②--子查询
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;