declare ind number; -- loop index
dph number; -- job handle
pct_done number; -- percentage complete
job_state varchar2(30); -- track job state
le ku$_logentry; -- wip and error messages
js ku$_jobstatus; -- job status from get_status
jd ku$_jobdesc; -- job description from get_status
sts ku$_status; -- status object returned by get_status
begin -- create job
dph := dbms_datapump.attach('sys_export_schema_01','sys' ); /* dph := dbms_datapump.open('export','schema',null,'example5','latest');
-- specify dump file dbms_datapump.add_file(dph, 'example5.dmp', 'expimp', filetype => dbms_datapump.ku$_file_type_dump_file);
-- specify log file dbms_datapump.add_file(dph, 'example5.log', 'expimp_log', filetype => dbms_datapump.ku$_file_type_log_file);
-- specify export schema dbms_datapump.metadata_filter(dph, 'schema_expr', 'in (''a'')');
-- set parallelism dbms_datapump.set_parallel(dph, 2);
-- start job dbms_datapump.start_job(dph); */ -- monitor job
pct_done := 0; job_state := 'undefined'; while (job_state != 'completed') and (job_state != 'stopped') loop dbms_datapump.get_status(dph, dbms_datapump.ku$_status_job_error dbms_datapump.ku$_status_job_status dbms_datapump.ku$_status_wip, -1, job_state, sts);
js := sts.job_status;
-- if the percentage done changed, display the new value
if js.percent_done != pct_done then dbms_output.put_line('*** job percent done = ' || to_char(js.percent_done)); pct_done := js.percent_done; end if;
-- if any work-in-progress (wip) or error messages
-- were received for the job, display them.
if (bitand(sts.mask,dbms_datapump.ku$_status_wip) != 0) then le := sts.wip; else if (bitand(sts.mask,dbms_datapump.ku$_status_job_error) != 0) then le := sts.error; else le := null; end if; end if;
if le is not null then ind := le.first; while ind is not null loop dbms_output.put_line(le(ind).logtext); ind := le.next(ind); end loop; end if; end loop;
-- indicate that the job finished and detach from it.
dbms_output.put_line('job has completed'); dbms_output.put_line('final job state = ' || job_state); dbms_datapump.detach(dph); exception when others then dbms_datapump.stop_job(dph); end; /
|