• 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;
    /

  • 相关阅读:
    史上自定义 JavaScript 函数Top 10
    switch
    (不)扩展内置原型((Not) Augmenting Built-in Prototypes)
    for-in循环(for-in Loops)
    for
    在dreamweaver中设置php服务器F12预览的方法介绍
    method
    CSS中background-image【CSS Sprites,base64编码】
    shell编程中的小问题
    常见的linux问题积累
  • 原文地址:https://www.cnblogs.com/tracy/p/2089170.html
Copyright © 2020-2023  润新知