In Oracle, "case when" is used to determine the multi-state situation of a field. The syntax is "case column name when condition value 1 then option 1 when condition value 2 then option 2...else default value end ".
The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.
oracle case when usage
Case has two formats. Simple Case function and Case search function.
Usage of Case when in Oracle:
(a) Starts with case and ends with end;
(b) When is followed by condition, then displays the result ;
(c) else is the default case, similar to the switch case in high-level language programs. The default can be omitted;
(d) end is followed by an alias;
Case has two kinds of expressions:
(A) Simple case expressions use expressions to determine the return value;
(B) Search case expressions and use conditions to determine the return value Value;
First format: Simple Case function:
Format description
case 列名 when 条件值1 then 选项1 when 条件值2 then 选项2....... else 默认值 end
eg:
select case job_level when '1' then '1111' when '2' then '1111' when '3' then '1111' else 'eee' end from dbo.employee
Second format:Case search function
Format description
case when 列名= 条件值1 then 选项1 when 列名=条件值2 then 选项2....... else 默认值 end
eg:
update employee set e_wage = case when job_level = '1' then e_wage*1.97 when job_level = '2' then e_wage*1.07 when job_level = '3' then e_wage*1.06 else e_wage*1.05 end
Recommended tutorial: "Oracle Video Tutorial"
The above is the detailed content of What is the usage of case when in oracle. For more information, please follow other related articles on the PHP Chinese website!