280 likes | 411 Views
Migrating Stored Procedures and Triggers. Objectives. After completing this lesson, you should be able to do the following: Identify PL/SQL objects Compare and contrast SQL Server and Oracle triggers Use OMWB to migrate stored procedures and triggers
E N D
Objectives • After completing this lesson, you should be able to do the following: • Identify PL/SQL objects • Compare and contrast SQL Server and Oracle triggers • Use OMWB to migrate stored procedures and triggers • Identify manual conversion tasks to complete PL/SQL code migration • Identify configuration options that affect PL/SQL performance
Oracle PL/SQL • Procedural Language/Structured Query Language (PL/SQL) is a fourth-generation programming language (4GL). PL/SQL provides: • Procedural extensions to SQL • Exception handling • Portability across platforms and products • Support for object-oriented programming • PL/SQL: • Is similar to SQL Server’s Transact-SQL (T-SQL) • Uses different syntax
PL/SQL Objects • There are many types of PL/SQL database objects: • Procedure • Function • Trigger • Package • Package body • Type body
Procedures • Procedures are used to perform a specific action. Procedures: • Transfer values in and out through an argument list • Are called with the CALLcommand
Packages • Packages are collections of functions and procedures. Each package should consist of two objects: • Package specification • Package body
SQL Server: Views Triggers Stored procedures Oracle: Views Triggers Procedures Functions Packages Package body Package type Migrating SQL Server Objects
Migrating T-SQL Objects Workflow 1 Map to PL/SQL objects. 2 Resolve parser errors. Oracle Model Source Model Create objects. 3 Perform manual conversion tasks. 4 Destination database PL/SQL editor
Migration Workbench Parser • The Migration Workbench parser converts T-SQL code to PL/SQL code by emulation. It: • Supports majority of the T-SQL language constructs • Converts most of stored procedures, triggers, and views successfully OMWB parser
Example: SQL Server Stored Procedure SQL> CREATE PROCEDURE dbo.example1 2 AS 3 BEGIN 4 RETURN 1 5 END
Example: Generated Stored Procedure in PL/SQL SQL> CREATE OR REPLACE FUNCTION EXAMPLE1 2 RETURN INTEGER 3 AS 4 StoO_selcnt INTEGER; 5 StoO_error INTEGER; 6 StoO_rowcnt INTEGER; 7 StoO_crowcnt INTEGER := 0; 8 StoO_fetchstatus INTEGER := 0; 9 StoO_errmsg VARCHAR2(255); 10 StoO_sqlstatus INTEGER; 11 BEGIN 12 BEGIN 13 RETURN 1; 14 END; 15 END EXAMPLE1; Function Errorhandling variables Extra BEGINand END block
Resolving Parser Errors • To resolve parser errors, perform the following steps: • Locate the error in the T-SQL code. • Change the Parse Options settings and re-parse the object. • Modify the T-SQL code and re-parse the object.
Step 3: Modifying T-SQL Code Example Double quotation marks not recognized by parser
Step 3: Modifying T-SQL Code Insert placeholder. 2 Comment out problematic codewith error notation. 1
Generated PL/SQL Object PL/SQL code for cursor
Migrating T-SQL Objects Workflow 1 Map to PL/SQL objects. 2 Resolve parser errors. Oracle Model Source Model Create objects. 3 Perform manual conversion tasks. 4 Destination database PL/SQL editor
Performing Manual Conversion Tasks • Manual tasks to complete PL/SQL migration : • Modify the PL/SQL source code to ensure the following: • Readability and ease of maintenance • Logically correct • Performance improvements • Verify that the procedures compile and execute.
Common Migration Issues • Common T-SQL to PL/SQL migration issues: • SQL syntax • Dynamic SQL • Transactions handling • Error handling • Returning result sets
PL/SQL Configuration Options • There are several PL/SQL compiler settings that control PL/SQL performance. • For the fastest performance, set: • PLSQL_CODE_TYPE=NATIVE • PLSQL_DEBUG=FALSE • PLSQL_OPTIMIZE_LEVEL=2 • PLSQL_WARNINGS=DISABLE:ALL
Summary • In this lesson, you should have learned how to: • Identify PL/SQL objects • Compare and contrast SQL Server and Oracle triggers • Use Migration Workbench to migrate stored procedures and triggers • Identify manual conversion tasks to complete PL/SQL code migration • Identify configuration options that affect PL/SQL performance
Practice Overview:Migrating Stored Procedures and Triggers • This practice covers the following topics: • Using OMWB to convert T-SQL objects to PL/SQL objects • Using OMWB to migrate the remaining schema objects to the Oracle database • Using Enterprise Manager to manually modify PL/SQL code • Verifying that the migrated PL/SQL code compiles and executes