Oracle 中 decode 函数用法(字段A,B, C,A不为空则取A,否则取B,B为空则取C)
程序员文章站
2022-06-22 22:14:32
–decode(条件,值1,返回值1,值2,返回值2,…值n,返回值n,缺省值) SELECT DECODE(TEMP.SCORE, ‘A’, ‘90-100’, ‘B’, ‘80-89’, ‘C’, ‘70-79’, ‘D’, ‘60-69’, ‘E’, ‘0-59’, ‘其他’) AS XXX ......
–decode(条件,值1,返回值1,值2,返回值2,…值n,返回值n,缺省值)
select decode(temp.score,
‘a’,
‘90-100’,
‘b’,
‘80-89’,
‘c’,
‘70-79’,
‘d’,
‘60-69’,
‘e’,
‘0-59’,
‘其他’) as xxx
from (select ‘a’ score from dual) temp
–结果:’90-100’
–decode(条件,比较值,值1,值2)
–当条件的值等于比较值时,该函数返回值1,否则返回值2
select decode(null,
temp.a,
decode(null, temp.b, decode(null, temp.c, ”, temp.c), temp.b),
temp.a) as xxx
from (select null a, ‘b’ b, ‘c’ c from dual) temp
select decode(temp.a,
null,
decode(temp.b, null, decode(temp.c, null, ”, temp.c), temp.b),
temp.a) as xxx
from (select null a, null b, ‘c’ c from dual) temp
上一篇: redis环境部署
下一篇: MongoDB 副本集丢失数据的测试