Intermediate

30-8.

One of a DBA’s tasks is to ensure that Oracle’s cost-based optimizer is using up-to-date statistics. Luckily, this task can be automated using a combination of two of Oracle’s built-in packages, DBMS_ JOB and DBMS_UTILITY.

Write a procedure that analyzes a specific schema to create statistics for the cost-based optimizer. This procedure will be submitted hourly by DBMS_ JOB. At 1:00 A.M. and 2:00 A.M., perform a complete analysis; otherwise, do it only for the indexes.

30-9.

Oracle8 introduced partitioned tables and indexes that are both a DBA’s dream and a DBA’s nightmare. They are a dream because they distribute system I/O and allow maintenance to be performed without causing all data to be unavailable. They can be nightmarish if they are used to perform business logic, as in the following exercise where no account transactions can be entered for a given month until after the 20th day of the previous month.

Suppose that a table called account_trx is created and partitioned as shown here:

CREATE TABLE account_trx
(account_no NUMBER,
 trx_amt    NUMBER,
 trx_date   DATE)
PARTITION BY RANGE (trx_date)
(PARTITION trx_199812 VALUES LESS THAN (to_date('01-JAN-1999',
                                           'DD-MON-YYYY')),
 PARTITION trx_199901 VALUES LESS THAN (to_date('01-FEB-1999',
                                           'DD-MON-YYYY')),
 PARTITION trx_199902 VALUES LESS THAN (to_date('01-MAR-1999',
                                           'DD-MON-YYYY')))
/

Write a procedure that sets up a job to run on the 20th of each month to create the partition for that month’s data.

Get Oracle PL/SQL Programming: A Developer's Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.