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; /
|