terça-feira, 15 de fevereiro de 2011

FORALL Support for Non-Consecutive Indexes

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


 

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;

Fonte: http://www.oracle-base.com/articles/10g/PlsqlEnhancements10g.php

Nenhum comentário :

Postar um comentário

Related Posts Plugin for WordPress, Blogger...