zoukankan      html  css  js  c++  java
  • FORALL Support for NonConsecutive Indexes (Sparse Collections)

    Oracle 10g introduces support for the FORALL syntax with non-consecutive indexes in collections. The INDICES OFclause allows the FORALL syntax to be used with sparse collections, while the VALUE OF clause is used for collections of indexes pointing to other collections. The following are examples of their usage.

    /* Formatted on 06/24/2011 4:56:22 PM (QP5 v5.163.1008.3004) */
    DROP TABLE tab1;

    CREATE TABLE tab1
    AS
       SELECT   1 id
         FROM   DUAL
        WHERE   1 = 0;

    DECLARE
       TYPE t_tab1 IS TABLE OF tab1%ROWTYPE;

       TYPE t_tab2 IS TABLE OF BINARY_INTEGER;

       l_tab1   t_tab1 := t_tab1 ();
       l_tab2   t_tab2 := t_tab2 ();
    BEGIN
       FOR i IN 1 .. 1000
       LOOP
          l_tab1.EXTEND;
          l_tab1 (l_tab1.LAST).id := i;

          IF MOD (i, 100) = 0
          THEN
             l_tab2.EXTEND;
             l_tab2 (l_tab2.LAST) := i;
          END IF;
       END LOOP;

       l_tab1.delete (301);
       l_tab1.delete (601);
       l_tab1.delete (901);

       -- This would fail due to sparse collection.
       --FORALL i IN l_tab.first .. l_tab.last
       --  INSERT INTO tab1 VALUES l_tab(i);

       -- This works fine with sparse collections.
       FORALL i IN INDICES OF l_tab1
          INSERT INTO   tab1
               VALUES   l_tab1 (i);

       -- This works fine for collections of indexes
       -- pointing to elements of another collection.
       FORALL i IN VALUES OF l_tab2
          INSERT INTO   tab1
               VALUES   l_tab1 (i);
    END;
    /

  • 相关阅读:
    Python字符串的定义与常用操作
    Python中yield返回生成器的详细方法
    python中把列表中的字符串转成整型的3种方法
    python基础教程:修改Python列表中元素的几种方法
    极致性能设计——开篇
    MySQL设计与实现
    Java平台标准版工具参考
    为什么for循环中的a=a++,a总是0
    JVM 分析工具快速查询手册
    从现代计算机低层看待性能和并发
  • 原文地址:https://www.cnblogs.com/tracy/p/2089170.html
Copyright © 2011-2022 走看看