oracle中decode的用法(例子)

使用結構:函數


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

相關文章
相關標籤/搜索