Home  >  Article  >  Database  >  What is the usage of case when in oracle

What is the usage of case when in oracle

2022-03-02 14:12:1855023browse

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 ".

What is the usage of case when in oracle

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

What is the usage of case when in oracle

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


    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

    when 列名= 条件值1 then 选项1
    when 列名=条件值2 then 选项2.......
    else 默认值 end


    update employee
    set e_wage =
    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

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!

The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn