Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/nvasilev/public_html/tech/wp-content/themes/suffusion/functions/media.php on line 666

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/nvasilev/public_html/tech/wp-content/themes/suffusion/functions/media.php on line 671

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/nvasilev/public_html/tech/wp-content/themes/suffusion/functions/media.php on line 684

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/nvasilev/public_html/tech/wp-content/themes/suffusion/functions/media.php on line 689

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/nvasilev/public_html/tech/wp-content/themes/suffusion/functions/media.php on line 694

Warning: Cannot modify header information - headers already sent by (output started at /home/nvasilev/public_html/tech/wp-content/themes/suffusion/functions/media.php:666) in /home/nvasilev/public_html/tech/wp-content/plugins/disable-xml-rpc-pingback/disable-xml-rpc-pingback.php on line 51
sql – Nikolay´s Technical Blog
Aug 232013
 

In PL/SQL, in order to iterate over a list of values (numbers, strings etc.) which aren’t fetched by a table, view, etc., you need to do the following:

DECLARE
  -- 1. declare a list type
  TYPE STR_LIST_TYPE IS TABLE OF VARCHAR2(15);

  -- 2. declare the variable of the list
  V_STR_VALUES STR_LIST_TYPE;

  -- 3. optional variable to store single values
  V_STR_VALUE VARCHAR2(15);

BEGIN

  -- 4. initialize the list of values to be iterated in a for-loop
  V_STR_VALUES := STR_LIST_TYPE('String 1','String 2');

  -- 5. iterating over the values
  FOR INDX IN V_COLUMN_NAMES.FIRST..V_COLUMN_NAMES.LAST
  LOOP
  
    -- 6. accessing the value itself
    V_STR_VALUE := V_STR_VALUES(INDX);
    
  END LOOP;     
END;
Share Button