使用结构:


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;

oracle中decode的用法(例子)

 

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

 oracle中decode的用法(例子)

 

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

 

 

相关文章:

  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
相关资源
相似解决方案