Oracle 流程控制语句

本文通过几个具体的示例介绍了PL/SQL中流程控制语句的应用,包括条件判断(IF)、选择结构(CASE)、循环(LOOP、WHILE、FOR)及跳转语句(GOTO)。每个示例都展示了如何在Oracle数据库环境中使用这些控制结构来实现特定的数据处理任务。

  --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;
   <<line_1>>
     null;-- DBMS_output.put_line('错误');
 end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值