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;

    输出结果

    平时多记记,到用时才能看看,记录你的进步,分享你的成果
  • 相关阅读:
    oracle执行计划相关
    RENAME方法进行分区改造
    在线重定义方法进行分区改造
    SYSAUX表空间如何清理
    Linux7安装Oracle 11g 86%报错:Error in invoking target 'agent nmhs' of makefile
    存储过程收集统计信息ORA-20000报错解决记录
    GIT-远程仓库
    GIT-本地仓库
    Python-DDT实现接口自动化
    Python-DDT框架
  • 原文地址:https://www.cnblogs.com/xielong/p/15165813.html
Copyright © 2011-2022 走看看