Oct 242013
 

Printing messages in the console working with SQL Developer is done in the following way:

  1. In the tab Dbms Output choose:
    dbms-out-console-enable
  2. Chose the connection:
    dbms-out-select-connection
  3. Running a small test:
    DECLARE
    BEGIN
      DBMS_OUTPUT.PUT_LINE('boo');
    END;
    /
    

Съответно нашия низ бива отпечатан в конзолните прозорци Script Output и Dbms Output:

anonymous block completed
boo
Share Button
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