0
点赞
收藏
分享

微信扫一扫

PL/SQL Case 与 Searched CASE 语句操作实例讲解

PL/SQL Case 与 Searched CASE 语句解释说明如下:

​​Case 语句​​


像IF语句中,CASE语句选择要执行的语句一个序列。但是选择顺序,CASE语句使用一个选择而不是多个布尔表达式。一个选择器其值被用来选择多个选项之一的表达式

​​Searched CASE 语句​​


所搜索的CASE语句没有选择,它的WHEN子句包含产生布尔值的搜索条件。

PL/SQL  Case 与 Searched CASE 的语法再操作实例源码中有赘述,在此不做解释,源码如下:

-- Created on 2018/3/23 by E.WANG 
--对两个书进行加、减、乘、除、乘方运算

declare
--运算符号
operrator varchar(2);
begin
/*
在PL/SQLcase语句语法是:
CASE selector
WHEN 'value1' THEN S1;
WHEN 'value2' THEN S2;
WHEN 'value3' THEN S3;
...
ELSE Sn; -- default case
END CASE;
*/
declare
one_int integer:=10;
two_int integer:=2;
resutl double precision;
begin
operrator:='+';
case operrator
when '**' then
resutl:=one_int**two_int;
dbms_output.put_line('Case---Power operrator: ' ||resutl );
when '/' then
resutl:=one_int/two_int;
dbms_output.put_line('Case---Div operrator: ' || resutl);
when '-' then
resutl:=one_int-two_int;
dbms_output.put_line('Case---Sub operrator: ' || resutl);
when '*' then
resutl:=one_int*two_int;
dbms_output.put_line('Case---Mul operrator: ' || resutl);
when '+' then
resutl:=one_int+two_int;
dbms_output.put_line('Case---Add operrator: ' || resutl);
else
dbms_output.put_line('Case---Invalid operrator!');
end case;
end;

/*
在PL/SQL搜查case语句语法是:
CASE
WHEN selector = 'value1' THEN S1;
WHEN selector = 'value2' THEN S2;
WHEN selector = 'value3' THEN S3;
...
ELSE Sn; -- default case
END CASE;
*/
declare
one_int integer:=10;
two_int integer:=2;
resutl double precision;
begin
operrator:='**';
case
when operrator='**' then
resutl:=one_int**two_int;
dbms_output.put_line('Search Case---Power operrator: ' ||resutl );
when operrator='/' then
resutl:=one_int/two_int;
dbms_output.put_line('Search Case---Div operrator: ' || resutl);
when operrator='-' then
resutl:=one_int-two_int;
dbms_output.put_line('Search Case---Sub operrator: ' || resutl);
when operrator='*' then
resutl:=one_int*two_int;
dbms_output.put_line('Search Case---Mul operrator: ' || resutl);
when operrator='+' then
resutl:=one_int+two_int;
dbms_output.put_line('Search Case---Add operrator: ' || resutl);
else
dbms_output.put_line('Search Case---Invalid operrator!');
end case;
end;

end;

窗口截屏如下:

PL/SQL Case 与 Searched CASE 语句操作实例讲解_Case语句使用实例

运行结果截图:

PL/SQL Case 与 Searched CASE 语句操作实例讲解_Case语句使用实例_02


举报

相关推荐

0 条评论