OracleDecode () Functions and CASE statements are often used. What are their differences? The following describes the differences between the OracleDecode () function and the CASE statement for your reference. First, let's give two simple examples to briefly compare the differences between the two. 1. CASE statement: The following is a code snippet: SELECTCASESIGN (5-5) W
Oracle Decode () Functions and CASE statements are often used. What are their differences? The following describes the differences between the Oracle Decode () function and the CASE statement for your reference. First, let's give two simple examples to briefly compare the differences between the two. 1. CASE statement: The following is a code snippet: SELECTCASESIGN (5-5) W
Oracle Decode () Functions and CASE statements are often used. What are their differences? The following is a detailed introduction
The difference between the Oracle Decode () function and the CASE statement is for your reference.
First, let's give two simple examples to briefly compare the differences between the two.
1. CASE statement:
The following is a code snippet:
Select case sign (5-5)
WHEN 1 THEN 'is Positive'
WHEN-1 THEN 'Is Negative'
ELSE 'is 0' END
From dual;
Background implementation:
The following is a code snippet:
If (SIGN (5-5) = 1 ){
Is Positive ';
} Else if (SIGN (5-5) = 2 ){
Is Negative ';
} Else {
Is Zero'
}
2. Decode function:
The following is a code snippet:
Select decode (SIGN (5-5), 1,
Is Positive,-1, Is Negative, Is Zero ')
FROMDUAL
Background implementation:
The following is a code snippet:
Switch (SIGN (5-5 ))
{
Case 1: 'Is Positive '; break;
Case 2: 'Is Negative '; break;
Default: 'Is 0'
}
In the above example, both of them can be implemented. However, the implementation of Decode () is quite complicated when encountering extraordinary problems.
For example:
The following is a code snippet:
The select case X-FIELD
WHEN X-FIELD <40 THEN 'x-FIELD <40'
WHEN X-FIELD <50 THEN 'x-FIELD <50'
WHEN X-FIELD <60 THEN 'x-FIELD <60'
ELSE 'unbeknown 'END
FROM DUAL
Therefore, I personally think that CASE statements are flexible in handling similar problems. Decode is more concise to match a small number of values.