Oracle is judged using Case...when statements.

Source: Internet
Author: User

Use the Case...when statement to determine its syntax in the following format:

Case<selector>

When<expression_1> then pl_sqlsentence_1;

When<expression_2> then pl_sqlsentence_2;

...

When<expression_n> then Pl_sqlsentence_n;

[Else plsql_sentence;]

End case;

Specific examples are as follows:

DeclareV_seasonint:=3; Autoinfovarchar2( -);begin   CaseV_season when 1  ThenAutoinfo:=V_season||'season includes 1, 2, March';  when 2  ThenAutoinfo:=V_season||'season includes 4, 5, June';  when 3  ThenAutoinfo:=V_season||'season includes 7, 8, September';  when 4  ThenAutoinfo:=V_season||'season includes 10, 11, December'; ElseAutoinfo:=V_season||'The seasons are illegal .'; End  Case; Dbms_output.put_line (autoinfo);End;

Output Result:

3 seasons including 7,8,9 month

In the use of case...when, only need to write a case on OK, can not write more than one, the wrong wording as follows:

DeclareV_seasonint:=3; Autoinfovarchar2( -);begin   CaseV_season when 1  ThenAutoinfo:=V_season||'season includes 1, 2, March';  CaseV_season when 2  ThenAutoinfo:=V_season||'season includes 4, 5, June';  CaseV_season when 3  ThenAutoinfo:=V_season||'season includes 7, 8, September';  CaseV_season when 4  ThenAutoinfo:=V_season||'season includes 10, 11, December'; ElseAutoinfo:=V_season||'The seasons are illegal .'; End  Case; Dbms_output.put_line (autoinfo);End;

If this is the case, the syntax is wrong and an error occurs when you run the PL/SQL block.

Oracle is judged with case...when statements

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.