首页  ·  知识 ·  数据库
Oracle流程控制语句
佚名  本站原创    编辑:dezai  图片来源:网络
--ifdeclareavgsal number;beginselect avg(sal) into avgsal from emp ;if avgsal 1500 thenDBMS_OUTPUT.PUT_LINE('达到最低

--if
declare
avgsal number;
begin
select avg(sal) into avgsal from emp ;
if avgsal >1500 then
DBMS_OUTPUT.PUT_LINE('达到最低标准')
else
update emp1 set sal=sal+100 ;
end if;
rollback;
end ;

--case
declare
score number;
begin
score:=&成绩;
case
when score<60 then DBMS_OUTPUT.PUT_LINE('挂了');
when score between 60 and 80 then DBMS_OUTPUT.PUT_LINE('通过');
when score between 81 and 100 then DBMS_OUTPUT.PUT_LINE('优秀');
else DBMS_OUTPUT.PUT_LINE('输入错误');
end case;
end ;

--loop
declare
i number :=1;
begin
loop
i:=i+i;
DBMS_OUTPUT.PUT_LINE(i);
exit when i>10;
end loop;
end ;

--while
declare
mixsal number;
begin
select max(sal) into mixsal from emp;
while mixsal<6000
loop
update emp set sal =sal+10;
select max(sal) into mixsal from emp;
end loop;
rollback;
end ;


---for
begin
for i in 1..1000
loop
insert into dumpy values(i ,dbms_random.string('x',8),dbms_random.random());
end loop;
end ;

--goto
declare
score number;
begin
score:=&score;
if score <0 or score>100 then
goto line_1;
else
DBMS_output.put_line('正确');
return;
end if;
<>
null;-- DBMS_output.put_line('错误');
end;

本文作者:佚名 来源:本站原创
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读