zoukankan      html  css  js  c++  java
  • Oracle/for loop循环如何进行跳过、跳出操作

    Oracle 的 for odr in(查询语句) loop 如何跳过循环、跳出循环, 利用循环产品列表进行不同操作

    1)loop循环的跳过

      --定义变量
    declare searchCount integer;
    begin   
         --赋值
          searchCount:=20;
         --循环产品列表信息,进行各种操作
         for odr in(select * from DXC_GOODS where MID <=searchCount)loop      
             if odr.MID=10 or odr.MID=15 then
                 dbms_output.put_line('跳过循环');
                 continue;
             elsif odr.MID=12 then
                  dbms_output.put_line('插入操作,ID:'|| odr.MID || ',Name:'|| odr.NAME);
                  --insetSql
             else
                  dbms_output.put_line('修改操作,ID:'|| odr.MID || ',Name:'|| odr.NAME);
                  --updateSql 
             end if;         
         end loop;
    end;

    输出结果

    2)loop循环的跳出

    --定义变量
    declare searchCount integer;
    begin   
         --赋值
          searchCount:=20;
         --循环产品列表信息,进行各种操作
         for odr in(select * from DXC_GOODS where MID <=searchCount)loop      
             if odr.MID=12 then
                  dbms_output.put_line('插入操作,ID:'|| odr.MID || ',Name:'|| odr.NAME);
                  --insetSql
             elsif odr.MID=20 then
                  dbms_output.put_line('跳出循环');
                  exit;
             else
                  dbms_output.put_line('修改操作,ID:'|| odr.MID || ',Name:'|| odr.NAME);
                  --updateSql 
             end if;         
         end loop;
    end;

    输出结果

     3)loop循环的跳过、跳出

    --定义变量
    declare searchCount integer;
    begin   
         --赋值
          searchCount:=20;
         --循环产品列表信息,进行各种操作
         for odr in(select * from DXC_GOODS where MID <=searchCount)loop      
             if odr.MID=10 or odr.MID=15 then
                 dbms_output.put_line('跳过循环');
                 continue;
             elsif odr.MID=12 then
                  dbms_output.put_line('插入操作,ID:'|| odr.MID || ',Name:'|| odr.NAME);
                  --insetSql
             elsif odr.MID=20 then
                  dbms_output.put_line('跳出循环');
                  exit;
             else
                  dbms_output.put_line('修改操作,ID:'|| odr.MID || ',Name:'|| odr.NAME);
                  --updateSql 
             end if;         
         end loop;
    end;

    输出结果

    平时多记记,到用时才能看看,记录你的进步,分享你的成果
  • 相关阅读:
    Eclipse配置方法注释模板
    彻底清除Github上某个文件以及历史
    eclipse快捷键
    Hibernate执行原生SQL
    API接口规范
    eclipse配置google代码风格
    eclipse format xml
    git撤销commit
    使用postman测试文件上传
    centos7下部署elasticSearch集群
  • 原文地址:https://www.cnblogs.com/xielong/p/15165813.html
Copyright © 2011-2022 走看看