zoukankan      html  css  js  c++  java
  • oracle for loop

     我们在Oracle存储过程中需要遍历一张表,应该怎样做。我想大多少的人第一个念头就是Cursor。

      比如:

      create or replace procedure StudyCursor(

      resulst out integer

      ) is

      v_tablename varchar(30);

      v_tabletype varchar(11);

      cursor mycursor is select * from cat;

      begin

      open mycursor;

      loop

      fetch mycursor into v_tablename,v_tabletype;

      null; --you can use tablename and v_tabletype

      end loop;

      close mycursor;

      end StudyCursor;

      最近在看代码是,发现其实我们还有一个更方便的方法就是使用for in loop … end loop

      create or replace procedure StudyFor(

      resulst out integer

      ) is

      begin

      for emm in(select * from cat) loop

      null; --you can use emm.table_name and emm.table_type

      end loop;

      return ;

      end StudyFor;

      是不是更方便,我要使用的查询结果,只需使用emm.table_name和emm.table_type即可。

      查找了Oracle的官方文档,似乎没有看见for loop的此种用法。确实很奇妙,只是不知道oracle内部具体的实现方法。

  • 相关阅读:
    Git 在Idea下的操作
    负载均衡算法-java实现
    MySQL 上亿大表优化实践 转
    盘点 10 个代码重构的小技巧
    wireshark抓包工具详细说明及操作使用
    限流
    Semaphore
    CyclicBarrier
    CountDownLatch和枚举配合使用
    ReentrantReadWriteLock读写锁
  • 原文地址:https://www.cnblogs.com/kenwong/p/3586844.html
Copyright © 2011-2022 走看看