oracle中 decode 与 case 执行效率问题

[复制链接]
查看11 | 回复5 | 2014-2-18 16:42:02 | 显示全部楼层 |阅读模式
请教个问题,
oracle 中decode 与 case 那个执行效率较高
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
CASE statements are similar in purpose to the DECODE statement, but they offer more flexibility and logical power. They are also easier to read than traditional DECODE statements, and offer better performance as well.
或者自己测试下也行!
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
大多数用case ,SQL 92标准
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
简单作了一个10053 ,执行计划都一样,可能在具体的例子中会有差别:
SELECT 'D' "DECODE('A','B','C','D')" FROM "SYS"."DUAL" "DUAL"
***************************************
GENERAL PLANS
***************************************
Considering cardinality-based initial join order.
***********************
Join order[1]:DUAL[DUAL]#0
***********************
Best so far: Table#: 0cost: 2.0012card: 1.0000bytes: 0
(newjo-stop-1) k:0, spcnt:0, perm:1, maxperm:80000
*********************************
Number of join permutations tried: 1
*********************************
Final - All Rows Plan:Best join order: 1
Cost: 2.0012Degree: 1Card: 1.0000Bytes: 0
Resc: 2.0012Resc_io: 2.0000Resc_cpu: 7271
Resp: 2.0012Resp_io: 2.0000Resc_cpu: 7271
kkoipt: Query block SEL$1 (#0)
--------------------------------------------------------------------
SELECT CASE 'A'
WHEN 'B' THEN

'C'
ELSE

'D'
END CASE
FROM DUAL
***************************************
GENERAL PLANS
***************************************
Considering cardinality-based initial join order.
***********************
Join order[1]:DUAL[DUAL]#0
***********************
Best so far: Table#: 0cost: 2.0012card: 1.0000bytes: 0
(newjo-stop-1) k:0, spcnt:0, perm:1, maxperm:80000
*********************************
Number of join permutations tried: 1
*********************************
Final - All Rows Plan:Best join order: 1
Cost: 2.0012Degree: 1Card: 1.0000Bytes: 0
Resc: 2.0012Resc_io: 2.0000Resc_cpu: 7271
Resp: 2.0012Resp_io: 2.0000Resc_cpu: 7271
kkoipt: Query block SEL$1 (#0)
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
看具体情况。
回复

使用道具 举报

千问 | 2014-2-18 16:42:02 | 显示全部楼层
写个循环执行下看看
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行