『ORACLE』 PLSQL-case语句(11g)

Posted 九號客栈

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了『ORACLE』 PLSQL-case语句(11g)相关的知识,希望对你有一定的参考价值。

语法:

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‘ THEN ‘The mark is 90-100‘
8 WHEN ‘B‘ THEN ‘The mark is 80-90‘
9 WHEN ‘C‘ THEN ‘The mark is 70-80‘
10 WHEN ‘D‘ THEN ‘The mark is 60-70‘
11 WHEN ‘E‘ THEN ‘The mark is 0-60‘
12 END;
13 dbms_output.put_line(res);
14 end;
15 /
The mark is 90-100

PL/SQL procedure successfully completed.

SQL> 2
2* mygrade char(1):=‘A‘;

SQL> ch /‘A‘/‘F‘/
2* 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‘ THEN ‘The mark is 90-100‘
8 WHEN ‘B‘ THEN ‘The mark is 80-90‘
9 WHEN ‘C‘ THEN ‘The mark is 70-80‘
10 WHEN ‘D‘ THEN ‘The mark is 60-70‘
11 WHEN ‘E‘ THEN ‘The mark is 0-60‘
12 END;
13 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‘ THEN ‘The mark is 90-100‘
8 WHEN ‘B‘ THEN ‘The mark is 80-90‘
9 WHEN ‘C‘ THEN ‘The mark is 70-80‘
10 WHEN ‘D‘ THEN ‘The mark is 60-70‘
11 WHEN ‘E‘ THEN ‘The mark is 0-60‘
12 ELSE ‘The mark is null‘
13 END;
14 dbms_output.put_line(res);
15 end;
16 /
The mark is null

PL/SQL procedure successfully completed.


















































以上是关于『ORACLE』 PLSQL-case语句(11g)的主要内容,如果未能解决你的问题,请参考以下文章

oracle11g中有执行语句和执行脚本,有啥区别?

SQL Merge 语句在 Oracle 11g 中有效,但在 9i 中无效

Oracle11g创建表空间语句

Oracle 11g 中的合并错误

ORA-00936: Oracle 11g 中的 DELETE 语句和视图缺少表达式

Oracle 11g的一些常用语句记录