Oracle to DB2 UDB Conversion Guide ISBN:0738499455 by Whei-Jen Chen et al IBM Redbooks © 2003 (448 pages) This informative guide describes how to migrate the database system from Oracle to DB2 UDB Version 8.1 on AIX, Linux, and the Microsoft Windows platform It presents the best practices in migration strategy and planning, migration tools, and more Table of Contents Oracle to DB2 UDB Conversion Guide Notices Preface Chapter 1 - Introduction Oracle Migration Project Chapter 2 Planning Chapter 3 - MTK Chapter 4 - Porting with MTK Chapter 5 - Conversion Reference Chapter 6 Chapter 7 Chapter 8 Chapter 9 - Data Conversion - Application Conversion - Script Conversion - Testing DB2 UDB Product Appendix A Overview Appendix B - Data Types Oracle Call Interface Appendix C (OCI) Mapping Converter for Appendix D SQL*Loader Appendix E - Terminology Mapping Appendix F - Example Oracle Database Appendix G - Additional Material Related Publications Index List of Figures List of Tables List of Examples Back Cover DB2 Universal Database (DB2 UDB) has long been known for its technology leadership This IBM Redbook is an informative guide that describes how to migrate the database system from Oracle to DB2 UDB Version 8.1 on AIX, Linux, and the Microsoft Windows platform This guide presents the best practices in migration strategy and planning, migration tools, and practical migration examples It is intended for technical staff who are involved in an Oracle to DB2 UDB conversion project This Redbook provides migration planning guidelines, with step-by-step instructions for installing and using IBM Migration Toolkits (MTK) to port the database objects and data from Oracle to DB2 UDB It illustrates with examples how to convert the stored procedures, functions, and triggers Application programming and conversion considerations are discussed along with the differences in features and functionality of the two products In addition, you can find script conversion samples for data loading, database administration, and reports, which are useful for DBAs The testing section provides procedures and tips for conversion testing and database tuning Oracle to DB2 UDB Conversion Guide Whei-Jen Chen Fadel Fiani Marina Greenstein Stefan Hummel Ranjit K Kalidasan Ken Leonard Art Sammartino Artur Wronski Redbooks ibm.com/redbooks Step-by-step guide to migrate from Oracle to DB2 UDB V8.1 Conversion examples Step-by-step guide of MTK tool usage Note Before using this information and the product it supports, read the information in "Notices" on page xv First Edition (November 2003) This edition applies to DB2 UDB Version 8.1, Fixpak 2, Oracle 8i, Oracle 9i, AIX 5.0, Linux Red Hat Version 8 Windows 2000 Server Copyright © International Business Machines Corporation 2003 ISBN:0738499455 All rights reserved Note to U.S Government Users Restricted Rights Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp Notices This information was developed for products and services offered in the U.S.A IBM may not offer the products, services, or features discussed in this document in other countries Consult your local IBM representative for information on the products and services currently available in your area Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead However, it is the user's responsibility to evaluate and verify the operation of any non-IBM product, program, or service IBM may have patents or pending patent applications covering subject matter described in this document The furnishing of this document does not give you any license to these patents You can send license inquiries, in writing, to: IBM Director of Licensing, IBM Corporation, North Castle Drive Armonk, NY 10504-1785 U.S.A The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you This information could include technical inaccuracies or typographical errors Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products This information contains examples of data and reports used in daily business operations To illustrate them as completely as possible, the examples include the names of individuals, companies, brands, and products All of these names are fictitious and any similarity to the names and addresses used by an actual business enterprise is entirely coincidental COPYRIGHT LICENSE: This information contains sample application programs in source language, which illustrates programming techniques on various operating platforms You may copy, modify, and distribute these sample programs in any form without payment to IBM, for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample programs are written These examples have not been thoroughly tested under all conditions IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs You may copy, modify, and distribute these sample programs in any form without payment to IBM for the purposes of developing, using, marketing, or distributing application programs conforming to IBM's application programming interfaces Trademarks The following terms are trademarks of the International Business Machines Corporation in the United States, other countries, or both: DRDA® Rational Suite® Redbooks (logo) Everyplace® Rational® iSeries™ Informix® Redbooks™ pSeries® IBM® RETAIN® z/OS® Lotus® S/390® Approach® MQSeries® SmartSuite® AIX 5L™ MVS™ SP2® AIX® Net.Data® SQL/DS™ AS/400® Notes® TestStudio® Distributed Relational Database OS/2® WebSphere® Architecture™ OS/390® 1-2-3® DB2 Connect™ OS/400® DB2 Extenders™ PartnerWorld® DB2 Universal Database™ QMF™ DB2® Rational Rose® The following terms are trademarks of International Business Machines Corporation and Rational Software Corporation, in the United States, other countries or both The following terms are trademarks of other companies: Intel, Intel Inside (logos), MMX, and Pentium are trademarks of Intel Corporation in the United States, other countries, or both Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc in the United States, other countries, or both UNIX is a registered trademark of The Open Group in the United States and other countries SET, SET Secure Electronic Transaction, and the SET Logo are trademarks owned by SET Secure Electronic Transaction LLC Other company, product, and service names may be trademarks or service marks of others Preface This IBM® Redbook provides procedures and examples of converting Oracle to DB2® UDB We focus on the technical considerations and methodology involved in performing the database and application conversion The laboratory examples are performed under Oracle 8i and DB2 UDB V8.1 However, the migration process and examples can be applied to Oracle 7, 8, and 9i The redbook is organized as follows Chapter 1 provides an overview of both Oracle and DB2 UDB to facilitate the understanding of both architectures Chapter 2 introduces the common process of migration and porting, the planning process, and the available tools and resources Chapter 3 describes the IBM Migration Toolkits functions and installation procedures Chapter 4 discuss and demonstrates the conversion of database objects and the extraction and loading of data into a DB2 UDB database using the IBM Migration Toolkit Chapter 5 explores some tools and methods for manually converting the triggers, store procedures, and functions It also provide examples of implementing SQL features in DB2 UDB, and technics in building external procedures and functions using C/C++ and Java™ Chapter 6 discusses the data conversion methods for deploying the data from Oracle to DB2 database Chapter 7 describes the application conversion from an Oracle to a DB2 UDB environment including planning, Proc*C, OCI, Java conversion, and package application migration such as SAP, PeopleSoft, and Siebel Chapter 8 discusses the administration script conversion from an Oracle environment to a DB2 UDB environment including data Chapter 9: Testing Table 9-1: Aggregations for data migration verification Table 9-2: List of monitor switches and related DBM parameters Table 9-3: Common snapshot table functions Table 9-4: Parameters for AUTOCONFIGURE command Appendix B: Data Types Table 9-5: Oracle to DB2 data type mapping Table 9-6: SQL data types mapped to Java declarations Table 9-7: Mapping Oracle data types to DB2 UDB data types Appendix C: Oracle Call Interface (OCI) Mapping Table 9-8: Connect/initialize/authorize Table 9-9: Handles/descriptors Table 9-10: Transaction management Table 9-11: Bind/define/describe Table 9-12: Prepare/execute/fetch Table 9-13: Miscellaneous Appendix E: Terminology Mapping Table 9-14: Oracle Terminology to DB2 UDB mapping List of Examples Chapter 4: Porting with MTK Example 4-1: Create database Example 4-2: Example of the create database command Example 4-3: Create table space command Example 4-4: Creating a table space of type Large Example 4-5: Creating a table space to store indexes Example 4-6: Granting Create table privilege to user smith Example 4-7: Trigger InsertEmployee Oracle source code Example 4-8: Trigger InsertEmployee DB2 conversion code Example 4-9: Trigger ManagersChange Oracle source Example 4-10: Trigger ManagersChange DB2 code Example 4-11: Alternative DB2 conversion of trigger ManagersChange Example 4-12: Trigger UpdateDepartments Oracle source code Example 4-13: DB2 conversion of trigger UpdateDepartments Example 4-14: InsertEmployee.db2 Example 4-15: EmployeeDynamicQuery Oracle source code Example 4-16: Converted DB2 code of Procedure EmployeeDynamicQuery Example 4-17: SelectRow Oracle source Example 4-18: SelectRow DB2 conversion Chapter 5: Conversion Reference Example 5-1: Simple Oracle trigger Example 5-2: Simple DB2 trigger Example 5-3: Oracle trigger with DML command Example 5-4: DB2 trigger with DML command Example 5-5: PL/SQL procedure with usage of DBMS_SQL Example 5-6: PL/SQL procedure with usage of native dynamic SQL Example 5-7: SQL PL procedure with native dynamic SQL Example 5-8: Dynamic UPDATE with EXECUTE IMMEDIATE Example 5-9: Dynamic UPDATE with EXECUTE and PREPARE Example 5-10: Java User Defined Function with dynamic SQL Example 5-11: Oracle procedure with explicit cursor Example 5-12: DB2 store procedure with cursor Example 5-13: Function with an explicit cursor in Oracle Example 5-14: Conversion using a FOR LOOP in DB2 Example 5-15: Oracle code using nested table Example 5-16: DB2 UDB code using DGTT Example 5-17: Efficient DB2 UDB code using DGTT Example 5-18: DB2 UDB code using INSERT INTO Example 5-19: PL/SQL procedure returns nested table Example 5-20: SQL Procedure returns multiple rows using CURSOR WITH RETURN Example 5-21: DB2 Store procedure calls AccountPackage.AccountList Example 5-22: Condition handler - SQL EXCEPTION Example 5-23: Condition handler - handle a long value Example 5-24: Condition handler - SIGNAL SQLSTATE Example 5-25: Oracle package with initialization Example 5-26: Oracle package with initialization as procedure Example 5-27: Definition of global variables in Oracle Example 5-28: Temporary table with global variables Example 5-29: Oracle hierarchical query Example 5-30: Computing of direct child data Example 5-31: Hierarchical query with entry point Example 5-32: Compute hierarchy level Example 5-33: Sample use of hierarchical query Example 5-34: Oracle outer joins Example 5-35: DB2 outer join conversion Example 5-36: Oracle code using RETURNING INTO Example 5-37: DB2 code using SELECT INTO Example 5-38: DB2 CODE using SELECT Example 5-39: DB2 dummy view for system information Example 5-40: Oracle function with a REF cursor Example 5-41: Conversion to a procedure with a Result Set in DB2 Example 5-42: Oracle procedure with Local function Example 5-43: DB2 Conversion of Oracle Procedure with Local Function Example 5-44: Stored Procedure in C Example 5-45: UDF Java source Chapter 6: Data Conversion Example 6-1: The data_unload.sh script Example 6-2: The desc.awk script Example 6-3: The count.awk script Example 6-4: Procedure to export_ table data Chapter 7: Application Conversion Example 7-1: Passing data to store procedure Example 7-2: Oracle JDBC connection Example 7-3: DB2 JDBC connection Example 7-4: Java call of Oracle or DB2 UDB procedure with input parameter Example 7-5: Java call of Oracle procedure with result set Example 7-6: Java call of DB2 UDB procedure with result set Example 7-7: Java call of Oracle procedure with input parameter and result set Example 7-8: Java call of DB2 UDB procedure with input parameter and result set Example 7-9: Java of Oracle function with input parameter and result set Chapter 8: Script Conversion Example 8-1: SQL*Loader control file with fixed-format fields Example 8-2: DB2 UDB Load file for table ACCOUNTS Example 8-3: SQL*Loader control file with variable-length fields Example 8-4: DB2 load commend with variable-length fields Example 8-5: SQL*Loader control file with conditions for table ACCOUNTS Example 8-6: Export script in Oracle Example 8-7: BACKUP database script in DB2 Chapter 9: Testing Example 9-1: Sample IMPORT messages Example 9-2: LOAD messages Example 9-3: Turning integrity checking back on Example 9-4: Table for storing number of rows (Oracle) Example 9-5: Table for storing number of rows (DB2) Example 9-6: Sample table CK_ROW_COUNTS contents Example 9-7: PL/SQL program that generates scripts for counting rows Example 9-8: Explaining error codes Example 9-9: Example of db2diag.log file Example 9-10: Example snapshot Example 9-11: Resetting snapshot monitor counters Example 9-12: Displaying monitor switches Example 9-13: Updating monitor switches at instance level Example 9-14: Updating monitor switches at application level Example 9-15: Database manager snapshot Example 9-16: Lock snapshot Example 9-17: Table snapshot Example 9-18: Table space and buffer pool snapshots Example 9-19: Dynamic SQL snapshot Example 9-20: Sample snapshot table function Example 9-21: Sample snapshot table function Example 9-22: Sample snapshot table function Example 9-23: Storing snapshot data in a table Example 9-24: Creating sample event monitor Example 9-25: Generating table syntax for specified event monitor Example 9-26: Enabling event monitor Example 9-27: Creating event monitor with file option Example 9-28: Formatting event monitor output files Example 9-29: Checking for current page allocation status Example 9-30: Enabling multi page allocation Example 9-31: Relocation of logical logs Example 9-32: Updating IO related processes Example 9-33: Increasing buffer pools Example 9-34: Resizing the transactional log Example 9-35: Invoking snapshot for locks on database sample Example 9-36: Lock escalation message in db2diag.log file Example 9-37: Current usage of log space by applications Example 9-38: Checking log I/O activity Example 9-39: Autoconfigure command Example 9-40: Finding indexes for particular query Appendix D: Converter for SQL*Loader Example 9-41: Conversion of Oracle control file to DB2 load command Example 9-42: Generation of additional DB2 update commands ... Drew Bradstock, Ted Wasserman, Bill Wilkins IBM DB2 UDB Consulting Services, Toronto Laboratory Alex Jarzebowicz IBM Data Management User Technology, IBM Silicon Valley Laboratory Dan Simchuk IBM World Wide Consulting - Data Management group... Chapter 8 discusses the administration script conversion from an Oracle environment to a DB2 UDB environment including data load script conversion, administration script conversion, and report tools available to DB2 Chapter 9 describes the test objectives and a generic testing... Art Sammartino Artur Wronski Redbooks ibm. com/redbooks Step-by-step guide to migrate from Oracle to DB2 UDB V8.1 Conversion examples Step-by-step guide of MTK tool usage Note Before using this information and the product it supports, read