PL/SQL idiom

jdavidb on 2003-09-17T19:10:43

In Perl:

foreach my $word (qw(this that whatever))
{
  dosomething($word);
}

In PL/SQL:

<>
DECLARE
  TYPE wordlist_t IS VARRAY(somenumber) OF
                     VARCHAR2(#);
  wordlist wordlist_t
    := wordlist_t('this', 'that', 'whatever');
BEGIN
  FOR i IN wordlist.FIRST .. wordlist.LAST
  LOOP
    dosomething(wordlist(i));
  END LOOP;
END foreach;


Or even...

petdance on 2003-09-17T19:43:35

do_something($_) foreach ( qw(this that other) );

Re:Or even...

jdavidb on 2003-09-18T04:36:23

Hmm, yeah, but usually I use the other form because I'm thinking of traversing the list. However, maybe that would read more naturally.

BTW, did I fail to get the joke? What's funny?

But if your array is zero...

jdavidb on 2006-07-19T21:02:09

This fails if your array has zero size.