Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

jdavidb
  (email not shown publicly)
http://voiceofjohn.blogspot.com/

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Wednesday May 03, 2006
09:28 AM

Oracle gem of the day: foreach in PL/SQL

[ #29513 ]

Of course, it ain't pretty, folks:

In Perl:

my @items = qw(item1 item2);
foreach my $item (@items)
{
  take_action($item);
}

In PL/SQL:

DECLARE
  TYPE items_t IS TABLE OF VARCHAR2(80);  -- note the strong typing constraint
  items items_t := items_t('item1', 'item2');
  items_index NUMBER := 1;
BEGIN
  <<items_loop>>
  WHILE items_index IS NOT NULL
  LOOP
    DECLARE
      item VARCHAR2(80) := items(items_index);
    BEGIN
      take_action(item);
      items_index := items.NEXT(items_index);
    END;
  END LOOP items_loop;
END;
/

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Note: this version [perl.org] has better syntax.

    --
    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers