Oracle Decode()函数和CASE语句都是我们经常用到的,那么它们的区别在哪里呢?下面就为您详细介绍Oracle Decode()函数和CASE语句的区别,供您参考。
首先,举2个简单的例子,简单对比一下这2者的区别。
1.CASE语句:
以下是代码片段:
#div_code img{border:0px;}<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> SELECT CASE SIGN(5 - 5)
WHEN 1 THEN 'Is Positive'
WHEN -1 THEN 'Is Negative'
ELSE 'Is Zero' END
FROM DUAL;
后台实现:
以下是代码片段:
#div_code img{border:0px;}<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> if (SIGN(5 – 5) = 1) {
'Is Positive';
} else if (SIGN(5 – 5) = 2 ) {
'Is Negative';
}else {
‘Is Zero’
}
2. Decode函数:
以下是代码片段:
#div_code img{border:0px;}<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> SELECT DECODE(SIGN(5 – 5), 1,
'Is Positive', -1, 'Is Negative', ‘Is Zero’)
FROMDUAL