–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