DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

6
10/09/13 Dev X: Use an Oracl e API to Ex tr act and Store Database Obj ects' DDL www.devx.com/print/dbzone/10MinuteSolution/21558/0/page/2 1/6 http://www.devx.com/dbzone/10MinuteSolution/21558 Use a n Oracle API to Extract and Store Database Objects' DDL-2 B y Boris Milrud Jul 21, 2004 here are times when database data manipulation requires extracting DDL (Data Definition Language) commands for various objects, such as database tables, indexes, constraints, triggers, etc. Recently I was charged with the task of writing a set of database packages to perform a high- performance massive DELETE operation. While my high-performance massive DELETE operation will be covered in my next solution, this month's solution explores the related technique of extracting and storing database objects' DDL. The method for extracting and storing database objects' DDL is as follows: Create a table with identical structure but with no primary key, alternate keys(s), and foreign keys(s) constraints. For instance, use MyTable_X, where MyTable is the target table for deletion. Insert data that needs to be kept into a newly created table (MyTable_X). Create indexes on your new table using the NOLOGGING PARALLEL options. Cr eate c onstraints on your new t abl e. Swap the MyTable and MyTable_X  tables. Rename your main table to MyTable_T and MyTable_X to MyTable. Verify the results and drop the MyTable_T t abl e. Obviousl y, in or der to write this c ode, you need to extract the dat abase object s' metadata (definitions and selected attributes) and store it in the memory, so it will be available while executing the above steps. There are numerous scripts available on the Web that extract database objects' metadata from the various Oracle dictionaries (user_tables, user_indexes, user_ind_columns, user_constraints, user_cons_columns, etc.), and then construct a DDL command for the object specified. One problem with these scripts is that they're usually SQL*Plus scripts that produce client-side text file, which is not accessible for database-side code. The main problem is that they are usually: Incomplete: not all of the numerous options are being extracted and incorporated into the DLL statement. Out-of-date: scripts usually do not support the latest Oracle database features— partitioning, function-based indexes, automatic segment space management (ASSM), etc. These scripts either crash or generate incorrect DDL statements. Though there are plenty of scripts available extract database objects' metadata from the various Oracle dictionaries, most of them are either incomplete or out-of-date. Learn how to perform the above task in the most optimal, error-free, and maintenance-free way using the DBMS_METADATA  pac k age.Using Orac le Native APIs: The DBMS_MET ADAT A Pac kage Oracle databases provide a rich set of prepackaged APIs in the form of Supplied PL/SQL Packages. One of the packages introduced in Oracle 9.2 version is exactly what you need: the

Transcript of DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

Page 1: DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

8/10/2019 DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

http://slidepdf.com/reader/full/devx-use-an-oracle-api-to-extract-and-store-database-objects-ddl 1/6

Page 2: DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

8/10/2019 DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

http://slidepdf.com/reader/full/devx-use-an-oracle-api-to-extract-and-store-database-objects-ddl 2/6

Page 3: DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

8/10/2019 DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

http://slidepdf.com/reader/full/devx-use-an-oracle-api-to-extract-and-store-database-objects-ddl 3/6

Page 4: DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

8/10/2019 DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

http://slidepdf.com/reader/full/devx-use-an-oracle-api-to-extract-and-store-database-objects-ddl 4/6

Page 5: DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

8/10/2019 DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

http://slidepdf.com/reader/full/devx-use-an-oracle-api-to-extract-and-store-database-objects-ddl 5/6

Page 6: DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

8/10/2019 DevX_ Use an Oracle API to Extract and Store Database Objects' DDL

http://slidepdf.com/reader/full/devx-use-an-oracle-api-to-extract-and-store-database-objects-ddl 6/6