它们的解析方式相同。
13:41:48 SYSTEM@oars_sandbox> create table t as select mod(rownum,5) val from dual connect by rownum <= 1e5;
Table created.
Elapsed: 00:00:00.21
注意“列投影信息”。第一种情况:
13:43:51 SYSTEM@oars_sandbox> ed
Wrote file S:\\tools\buffer.sql
1 SELECT CASE val
2 WHEN 1 THEN 'a'
3 WHEN 2 THEN 'a'
4 WHEN 3 THEN 'a'
5 WHEN 5 THEN 'b'
6 END AS case_column_str
7 FROM t
8* ORDER BY case_column_str
13:44:32 SYSTEM@oars_sandbox> @xplan
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------
Plan hash value: 961378228
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 114K| 1450K| | 591 (2)| 00:00:08 |
| 1 | SORT ORDER BY | | 114K| 1450K| 2256K| 591 (2)| 00:00:08 |
| 2 | TABLE ACCESS FULL| T | 114K| 1450K| | 44 (3)| 00:00:01 |
-----------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T@SEL$1
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - (#keys=1) CASE "VAL" WHEN 1 THEN 'a' WHEN 2 THEN 'a' WHEN 3 THEN
'a' WHEN 5 THEN 'b' END [1]
2 - "VAL"[NUMBER,22]
Note
-----
- dynamic sampling used for this statement (level=2)
第二种情况:
13:44:36 SYSTEM@oars_sandbox> ed
Wrote file S:\\tools\buffer.sql
1 SELECT CASE WHEN val=1 OR val=2 OR val=3 THEN 'a'
2 WHEN val=5 OR val=6 THEN 'b'
3 END AS case_column_str
4 FROM t
5* ORDER BY case_column_str
13:45:53 6
13:45:55 SYSTEM@oars_sandbox> @xplan
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------
Plan hash value: 961378228
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 114K| 1450K| | 591 (2)| 00:00:08 |
| 1 | SORT ORDER BY | | 114K| 1450K| 2256K| 591 (2)| 00:00:08 |
| 2 | TABLE ACCESS FULL| T | 114K| 1450K| | 44 (3)| 00:00:01 |
-----------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T@SEL$1
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - (#keys=1) CASE "VAL" WHEN 1 THEN 'a' WHEN 2 THEN 'a' WHEN 3 THEN
'a' WHEN 5 THEN 'b' END [1]
2 - "VAL"[NUMBER,22]
Note
-----
- dynamic sampling used for this statement (level=2)
解释计划查询:
select * from table(dbms_xplan.display(null, null, 'all'));