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

  • 相关阅读:
    js 数组分解 解构
    js math 对数和指数处理 expm1 log1p
    highcharts 坐标轴 数值 格式化
    libvirt-qemu-虚拟机设备热插拔
    Linux设备驱动程序加载/卸载方法 insmod和modprobe命令
    mount、umount、fuser命令使用小结
    Linux安全策略配置-pam_tally2身份验证模块
    python处理时间相关的方法
    python中命令行参数
    linux---(6/27)tr命令和sed命令详解
  • 原文地址:https://www.cnblogs.com/tracy/p/2089170.html
Copyright © 2020-2023  润新知