Sunday, January 3, 2016

Execute Immediate with Procedure



CREATE OR REPLACE PROCEDURE

show_number_values (

   table_in    IN VARCHAR2,

   column_in   IN VARCHAR2,

   where_in    IN VARCHAR2)

IS

   TYPE values_t IS TABLE OF
NUMBER;



   l_values   values_t;

BEGIN

   EXECUTE IMMEDIATE

         'SELECT '

      || column_in

      || ' FROM '

      || table_in

      || ' WHERE '

      || where_in

      BULK COLLECT INTO
l_values;



   FOR indx IN 1 ..
l_values.COUNT

   LOOP

      DBMS_OUTPUT.put_line

      (l_values (indx));

   END LOOP;

END;



And when I call the
procedure for the standard employees table

BEGIN

   show_number_values (

      'employees',

      'salary',

      'department_id = 10

       order by salary
desc');

END;

No comments:

Post a Comment