Grammar:
Case Selector
When Exp1 then Res1
When Exp2 then Res2
When Exp3 then Res3
...
[ELSE RESN]
End
Sql> Declare
2 Mygrade char (1): = ' A ';
3 res varchar2 (20);
4 begin
5 Res: =
6 Case Mygrade
7 when ' A ' and ' The mark is 90-100 '
8 when ' B ' and ' The mark is 80-90 '
9 when ' C ' and ' The mark is 70-80 '
When ' D ' and ' The mark is 60-70 '
Once ' E ' then ' the mark is 0-60 '
The END;
Dbms_output.put_line (RES);
The end;
15/
The Mark is 90-100
PL/SQL procedure successfully completed.
Sql> 2
Mygrade char (1): = ' A ';
sql> CH/' A '/' F '/
Mygrade char (1): = ' F ';
Sql> L
1 declare
2 Mygrade char (1): = ' F ';
3 res varchar2 (20);
4 begin
5 Res: =
6 Case Mygrade
7 when ' A ' and ' The mark is 90-100 '
8 when ' B ' and ' The mark is 80-90 '
9 when ' C ' and ' The mark is 70-80 '
When ' D ' and ' The mark is 60-70 '
Once ' E ' then ' the mark is 0-60 '
The END;
Dbms_output.put_line (RES);
14* end;
Sql>/
PL/SQL procedure successfully completed.
Sql> Declare
2 Mygrade char (1): = ' F ';
3 res varchar2 (20);
4 begin
5 Res: =
6 Case Mygrade
7 when ' A ' and ' The mark is 90-100 '
8 when ' B ' and ' The mark is 80-90 '
9 when ' C ' and ' The mark is 70-80 '
When ' D ' and ' The mark is 60-70 '
Once ' E ' then ' the mark is 0-60 '
The ELSE ' The mark is null '
The END;
Dbms_output.put_line (RES);
The end;
16/
The mark is null
PL/SQL procedure successfully completed.
"ORACLE" plsql-case statement (11g)