1.CASE中存在selector,不返回值
declare input_str varchar2(20):=('&str');
begin
case input_str
when 'A' then dbms_output.put_line(input_str||1);
when 'B' then dbms_output.put_line(input_str||2);
when 'C' then dbms_output.put_line(input_str||3);
when 'D' then dbms_output.put_line(input_str||4);
when 'E' then dbms_output.put_line(input_str||5);
else dbms_output.put_line('输入未知字符!');
end case;
end;
2.CASE中存在selector,作为表达式使用
declare input_str varchar2(20):=('&str');result_srtvarchar2(50);
begin
result_srt:=case input_str
when 'A' then input_str||1
when 'B' then input_str||2
when 'C' then input_str||3
when 'D' then input_str||4
when 'E' then input_str||5
else '输入未知字符!'
end;
dbms_output.put_line(result_srt);
end;
注意: case语句内允许有分号,以end的结束。
3.不使用CASE中的选择器搜索CASE
declare input_str varchar2(20):=('&str');result_srtvarchar2(50);
begin
result_srt:=case
when input_str='A'then input_str||1
when input_str='B'then input_str||2
when input_str='C'then input_str||3
when input_str='D'then input_str||4
when input_str='E'then input_str||5
else '输入未知字符!'
end;
dbms_output.put_line(result_srt);
end;
declare input_str varchar2(20):=('&str');
begin
case input_str
when 'A' then dbms_output.put_line(input_str||1);
when 'B' then dbms_output.put_line(input_str||2);
when 'C' then dbms_output.put_line(input_str||3);
when 'D' then dbms_output.put_line(input_str||4);
when 'E' then dbms_output.put_line(input_str||5);
else dbms_output.put_line('输入未知字符!');
end case;
end;
2.CASE中存在selector,作为表达式使用
declare input_str varchar2(20):=('&str');result_srtvarchar2(50);
begin
result_srt:=case input_str
when 'A' then input_str||1
when 'B' then input_str||2
when 'C' then input_str||3
when 'D' then input_str||4
when 'E' then input_str||5
else '输入未知字符!'
end;
dbms_output.put_line(result_srt);
end;
注意: case语句内允许有分号,以end的结束。
3.不使用CASE中的选择器搜索CASE
declare input_str varchar2(20):=('&str');result_srtvarchar2(50);
begin
result_srt:=case
when input_str='A'then input_str||1
when input_str='B'then input_str||2
when input_str='C'then input_str||3
when input_str='D'then input_str||4
when input_str='E'then input_str||5
else '输入未知字符!'
end;
dbms_output.put_line(result_srt);
end;