declare --声明
mynum number(3) := 0;
begin
loop
mynum := mynum + 1;
dbms_output.put_line(mynum); exit when mynum = 200; --退出循环条件
end loop;end;
--while循环
declare
i number := 1;begin
while i <= 100 loop --执行循环条件 dbms_output.put_line(i);
i := i + 1; end loop;end;
begin
for i in 1 .. 10 loop
dbms_output.put_line(i); end loop;end;
declare
i number := 1;begin
loop
dbms_output.put_line('i:'||i);
i := i + 1; if i > 100 then
goto biaoji; end if; end loop; <<biaoji>>
dbms_output.put_line('i:'||i);end;
declare
v_value1 number := 20;begin
if v_value1 < 10 then
dbms_output.put_line('v_value1小于10');
elsif v_value1 < 20 then --注意elsif 不是 else if
dbms_output.put_line('v_value1小于20'); else
dbms_output.put_line('v_value1大于或等于20'); end if;end;
declare
v_value1 varchar2(2) := 'A';
v_value2 varchar2(100);begin
v_value2 := case v_value1 when 'A' then
'优秀'
when 'B' then
'一般'
else
'差劲'
end;
dbms_output.put_line(v_value2);end;
declare
v_value1 varchar2(2) := 'A';
v_value2 varchar2(100);begin
v_value2 := case
when v_value1 = 'A' then
'优秀'
when v_value1 = 'B' then
'一般'
else
'差劲'
end;
dbms_output.put_line(v_value2);end;
以上两种方式都是可以的,这里注意了,case when语句 始终都都返回值(这点和if条件语句不一样)。
也可以用于查询结果和查询条件
select case t.c_type when 'B' then
'一般'
when 'A' then
'优秀'
else
'差劲'
end, case
when t.c_case_no = '4090003002115000012' then
'4090003002015000012'
end
from tbl_claim t where t.c_case_no = case
when t.c_case_no = '4090003002015000012' then
'4090003002015000012'
end;
decode(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)
select decode('A', 'B', '一般', 'A', '优秀', '差劲') from dual;
可用于查询结果和查询条件。(但是不能像case when一样赋值)
select decode(t.type, 'B', '一般', '差劲') from mytable t where t.c_no = decode(t.c_no, '111', '111', '222');
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。