Use dbms_job.submit to call 'execute immediate' : DBMS_JOB « System Packages « Oracle PL/SQL Tutorial






SQL> create table myTable (
  2   tname varchar2(30),
  3   cname varchar2(30),
  4   changed date
  5  );

Table created.

SQL>
SQL> create or replace procedure RUN_DDL(m varchar2) is
  2   pragma autonomous_transaction;
  3   begin
  4   execute immediate m;
  5   end;
  6  /
SQL>
SQL> create or replace procedure ADD_COLUMN(p_table varchar2, p_column varchar2) is
  2   v number;
  3   j number;
  4   begin
  5       insert into myTable values (p_table, p_column, sysdate);
  6       dbms_job.submit(j, 'run_ddl(''alter table '||p_table||' add '||p_column||''');');
  7   end;
  8  /

Procedure created.

SQL>
SQL>
SQL> drop table myTable;

Table dropped.








31.11.DBMS_JOB
31.11.1.DBMS_JOB demonstration
31.11.2.DBMS_JOB.SUBMIT
31.11.3.Submit a job and run
31.11.4.Submit a job and query the user_jobs
31.11.5.Job number
31.11.6.Use dbms_job.submit to call 'execute immediate'
31.11.7.Submit job to change password
31.11.8.Schedule the procedure to run now and every night at 3 AM: