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