–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
原文地址:https://www.cnblogs.com/fyhaoge/p/10906043.html
时间: 2024-10-10 17:00:33