Channels ▼
RSS

Tools

Databases and Refreshing Test Data


4. Cleanup Test Database

This procedure SCHEMA_REFRESH.CLEANUP, recompiles invalid objects that may have become invalid do to the import. It also drops scheduled jobs because they cannot be excluded from the export; therefore, it must be dropped after import; aee Listing 4.


procedure cleanup
as
 begin
       drop_jobs;
       validate_objects;
end cleanup;     

procedure drop_jobs
 as
 begin
   --
    --  just add a new entry for each schema
    --
    v_schema.delete(1);
    v_schema(1) := 'R11';
    
FOR i IN v_schema.FIRST..v_schema.LAST LOOP
       FOR t IN (SELECT owner, job_name
                FROM all_SCHEDULER_JOBS
                WHERE  owner = upper( v_schema(i) ) ) LOOP
             DBMS_SCHEDULER.DROP_JOB (job_name      => t.owner|| '.' || t.job_name);  
        END LOOP;     
   end loop;
   end drop_jobs;        
  procedure validate_objects 
as
 v_stmt varchar2(200);
begin
  FOR t IN (select owner, object_name, object_type
                from all_objects
                where owner in ('R11','WEB_USER')
                and status = 'INVALID'
                AND OBJECT_TYPE != 'SYNONYM') LOOP
               do_compile( t.owner, t.object_name, t.object_type);
           
        END LOOP;
end validate_objects;
CREATE OR REPLACE procedure do_compile( p_owner varchar2, p_object_name varchar2, p_object_type varchar2)
      as     
      begin
           EXECUTE IMMEDIATE 'alter  '||p_object_type||'   '|| p_owner || '.' || p_object_name||' compile';
      exception
       when others then
             null;
     end do_compile;

Listing 4: Cleanup

5. Send Email

The process is handled directly from: DBMS_SCHEDULER.CREATE_PROGRAM. This step will be explained later.

According to Oracle "The DBMS_SCEDULER package provides a collection of scheduling functions and procedures that are callable from any PL/SQL program." Go here for details on DBMS_SCEDULER.

Note: To administer job scheduling you need the privileges belonging to the SCHEDULER_ADMIN role. To create and run jobs in your own schema, you need the 'CREATE JOB' privilege.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video