Decode can only be equivalent, while casewhen can be used for range and condition differentiation. decode can do the same as casewhen. In terms of efficiency, I personally think
Decode can only be equivalent. case when can be used for range, range can be used for condition differentiation, and decode can be used for case when. In terms of efficiency, I personally think
CASE When in Oracle:
SELECT LogID, UserID, LogTime, Url, Description ,(
Case
When OperateType = 0 then 'add'
When OperateType = 1 then 'modify'
Else 'delete'
End) OperationName
FROM LOG
Decode () in Oracle ():
· Meaning:
Decode (condition, value 1, translation value 1, value 2, translation value 2,... value n, translation value n, default value)
SELECT LogID, UserID, LogTime, Url, Description,
Decode (OperateType, 0, 'add', 1, 'modify', 'delete') OperationName
FROM LOG
Difference: the two are similar in fixed comparison conditions, such as OperateType and fixed values 0, 1, and 2. However, when the comparison conditions are not fixed, for example, OperateType is changed to Sarlary, the case when is much easier if the range is 0-2000, 2000-or above.
In fact, decode and case when can often be equivalent. The choice of decode can be determined by the programmer's habits and proficiency. However, it is worth noting that the two forms of CaseWhen are listed as follows. I think the best analysis method is to write an SQL to test it. I will not talk about it here.
CASE expr WHEN comparison_expr1 THEN return_expr1
[WHEN comparison_expr2 THEN return_expr2
WHEN comparison_exprn THEN return_exprn
ELSE else_expr]
END
(A variant of case when)
CASE
WHEN comparison_expr1 THEN return_expr1
[WHEN comparison_expr2 THEN return_expr2
WHEN comparison_exprn THEN return_exprn
ELSE else_expr]
END
DECODE (col | expression, search1, result1
[, Search2, result2,...,]
[, Searchn, resultn,...,]
[, Default])
--------------------------------------------------------------------------------
Installing Oracle 12C in Linux-6-64
Install Oracle 11gR2 (x64) in CentOS 6.4)
Steps for installing Oracle 11gR2 in vmwarevm
Install Oracle 11g XE R2 In Debian
--------------------------------------------------------------------------------