7/10/13 SQL Translation OBE www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/12c_sqldev/sql_translation_sql_dev/sql_translation_sql_dev.html 1/36 Purpose This tutorial shows you how to use have an environment ready to demo the new Oracle Database 12c feature, SQL Translation Framework, which is used to aid in the migration of 3rd party database and applications to the Oracle database. In this OBE, you will migrate a Sybase ASE database and its associate Java application to Oracle 12c Database. This tutorial will show how to migrate a Java Sybase Application to run against Oracle Database with minimal code changes using the SQL Translation Framework. Time to Complete Approximately 90 minutes Introduction What Is SQL Developer? Oracle SQL Developer is a free graphical tool that enhances productivity and simplifies database development tasks. Using Oracle SQL Developer, you can browse database objects, run SQL statements, edit and debug PL/SQL statements and run reports, whether provided or created. Sybase Migration Overview Using Oracle SQL Developer, you can quickly migrate your third-party database to Oracle. There are four main steps in the database migration process: Capture the Source Database The first step is to capture a "snapshot" of the Sybase database. This can be done in two ways. 1. Online Capture: This requires creating a connection in SQL Developer to a live Sybase database. Using JDBC, the Sybase database metadata can be accessed and 2. Offline Capture: This involves BCP scripts generated by SQL Developer to extract the Sybase database metadata to files. These files can then be "captured" by SQL De The second method is what you will perform in this tutorial. Using SQL Developers Offline Capture feature, the pubs2 sample database has been extracted into offline data files. The files generated by the Capture tool contains the dat database. Oracle SQL Developer uses these files as the basis for building a representation of the structure of the source Sybase database. This structure is called the Captu Convert the Captured Database Oracle SQL Developer uses the Captured Model to convert the captured objects to Oracle-format objects, building up a representation of the structure of the destination datab Generate the Oracle Database Oracle SQL Developer generates DDL statements to create the new Oracle database, based upon the Converted Model objects. Running the DDL statements will result in th Migrate the Data The last step in the process is to migrate the data. You can do this in one of two ways. 1. Online Data Move: You can create a connection from within Oracle SQL Developer to your Sybase source database and migrate the data. 2. Offline Data Move: You can export the data from Sybase. SQL Developer will create a series of BCP and sqlldr files that you can run from a batch file. The second method is what you will perform in this tutorial. SQL Translation Framework SQL Translation Framework translates the SQL statements of a client application from a foreign (non-Oracle) SQL dialect into the SQL dialect used by the Oracle Database. In addition to translating non-Oracle SQL statements, the SQL Translation Framework can also be used to substitute an Oracle SQL statement with another Oracle statement to address a semantic or a performance issue. In this way, you can address an application issue without patching the client application.The SQL Translation framework is installed as part of Oracle Database installation. However, it must be configured to recognize the non-Oracle SQL dialect of the application and you must install at least one translator to fully utilize the framework. Before using the SQL Translation Framework, you should migrate your data, schema, stored procedures, triggers, and views. The SQL translation framework consists of the following two components: The SQL Translator : The SQL Translator is a software component, provided by Oracle or third-party vendors, which can be installed in Oracle Database. It translates the SQL statements of a client application before they are processed by the Oracle Database SQL compiler. If an error results from translated SQL statement execution, then Oracle Database SQL compiler generates an Oracle error message. The SQL Translator automatically translates non-Oracle SQL to Oracle SQL, thereby enabling the existing client-side application code to run largely unchanged against an Oracle Database. This reduces the cost of migration to Oracle Database significantly. The SQL Translation Profile: The SQL Translation Profile is a database object that contains the set of captured non-Oracle SQL statements, and their translations and translation errors.The SQL Translation Profile is used to review, approve, and modify translations. A SQL Translation Profile is associated to a single SQL Translator. However, a translator can be used in one or more SQL Translation Profiles. Typically, there is one SQL Translation Profile per application, otherwise applications can share translated queries. You can export profiles among various databases. Inside the Database, the SQL statements are translated by the SQL Translator, registered with the SQL Translation Profile, to handle the translation for the non-Oracle client application. Hardware and Software Requirements (Optional) The following is a list of hardware and software requirements: Oracle Database 12c SQL Developer 3.2.20_09 or later. Prerequisites Before starting this tutorial, you should: Download and install Oracle Database 12c. Download and unzip the files.zip file into your working directory (i.e.wkdir) Download and unzip the SQLApp.zip file into your desktop Before starting the OBE, please perform the following: Open the terminal Type : . oraenv To Make sure ORACLE_SID and ORACLE_HOME are set properly type: env | grep ORA Start sqlplus Enter username: sys as sysdba Enter Password: oracle SQL Developer persists information about the migration into a set of Oracle database tables called the migration repository. Its best to create a new user (mwrep) in the Oracle Overview Creating the mwrep User Setting up SQL Translation Framework OBE for Database 12cR1
36
Embed
Setting up SQL Translation Framework OBE for Database 12cR1 · There are four main steps in the database migration process: Capture the Source Database The first step is to capture
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
This tutorial shows you how to use have an environment ready to demo the new Oracle Database 12c feature, SQL Translation Framework, which is used to aid in the migration of
3rd party database and applications to the Oracle database. In this OBE, you will migrate a Sybase ASE database and its associate Java application to Oracle 12c Database. This
tutorial will show how to migrate a Java Sybase Application to run against Oracle Database with minimal code changes using the SQL Translation Framework.
Time to Complete
Approximately 90 minutes
Introduction
What Is SQL Developer?
Oracle SQL Developer is a free graphical tool that enhances productivity and simplifies database development tasks. Using Oracle SQL Developer, you can browse database
objects, run SQL statements, edit and debug PL/SQL statements and run reports, whether provided or created.
Sybase Migration Overview
Using Oracle SQL Developer, you can quickly migrate your third-party database to Oracle.
There are four main steps in the database migration process:
Capture the
Source
Database
The first step is to capture a "snapshot" of the Sybase database. This can be done in two ways.
1. Online Capture: This requires creating a connection in SQL Developer to a live Sybase database. Using JDBC, the Sybase database metadata can be accessed and
2. Offline Capture: This involves BCP scripts generated by SQL Developer to extract the Sybase database metadata to files. These files can then be "captured" by SQL Developer to create the Captured Model.
The second method is what you will perform in this tutorial.
Using SQL Developers Offline Capture feature, the pubs2 sample database has been extracted into offline data files. The files generated by the Capture tool contains the database schema information for the Sybase pubs2
database. Oracle SQL Developer uses these files as the basis for building a representation of the structure of the source Sybase database. This structure is called the Captured Model.
Convert the
Captured
Database
Oracle SQL Developer uses the Captured Model to convert the captured objects to Oracle-format objects, building up a representation of the structure of the destination database. This structure is called the Converted Model.
Generate the
Oracle DatabaseOracle SQL Developer generates DDL statements to create the new Oracle database, based upon the Converted Model objects. Running the DDL statements will result in the creation
Migrate the Data
The last step in the process is to migrate the data. You can do this in one of two ways.
1. Online Data Move: You can create a connection from within Oracle SQL Developer to your Sybase source database and migrate the data.
2. Offline Data Move: You can export the data from Sybase. SQL Developer will create a series of BCP and sqlldr files that you can run from a batch file.
The second method is what you will perform in this tutorial.
SQL Translation Framework
SQL Translation Framework translates the SQL statements of a client application from a foreign (non-Oracle) SQL dialect into the SQL dialect used by the Oracle Database. In
addition to translating non-Oracle SQL statements, the SQL Translation Framework can also be used to substitute an Oracle SQL statement with another Oracle statement to
address a semantic or a performance issue. In this way, you can address an application issue without patching the client application.The SQL Translation framework is installed as
part of Oracle Database installation. However, it must be configured to recognize the non-Oracle SQL dialect of the application and you must install at least one translator to fully
utilize the framework. Before using the SQL Translation Framework, you should migrate your data, schema, stored procedures, triggers, and views.
The SQL translation framework consists of the following two components:
The SQL Translator : The SQL Translator is a software component, provided by Oracle or third-party vendors, which can be installed in Oracle Database. It translates the SQL
statements of a client application before they are processed by the Oracle Database SQL compiler. If an error results from translated SQL statement execution, then Oracle Database
SQL compiler generates an Oracle error message. The SQL Translator automatically translates non-Oracle SQL to Oracle SQL, thereby enabling the existing client-side application
code to run largely unchanged against an Oracle Database. This reduces the cost of migration to Oracle Database significantly.
The SQL Translation Profile: The SQL Translation Profile is a database object that contains the set of captured non-Oracle SQL statements, and their translations and translation
errors.The SQL Translation Profile is used to review, approve, and modify translations. A SQL Translation Profile is associated to a single SQL Translator. However, a translator can
be used in one or more SQL Translation Profiles. Typically, there is one SQL Translation Profile per application, otherwise applications can share translated queries. You can export
profiles among various databases. Inside the Database, the SQL statements are translated by the SQL Translator, registered with the SQL Translation Profile, to handle the
translation for the non-Oracle client application.
Hardware and Software Requirements (Optional)
The following is a list of hardware and software requirements:
Oracle Database 12c
SQL Developer 3.2.20_09 or later.
Prerequisites
Before starting this tutorial, you should:
Download and install Oracle Database 12c.
Download and unzip the files.zip file into your working directory (i.e.wkdir)
Download and unzip the SQLApp.zip file into your desktop
Before starting the OBE, please perform the following:
Open the terminal
Type : . oraenv
To Make sure ORACLE_SID and ORACLE_HOME are set properly type: env | grep ORA
Start sqlplus
Enter username: sys as sysdba
Enter Password: oracle
SQL Developer persists information about the migration into a set of Oracle database tables called the migration repository. Its best to create a new user (mwrep) in the Oracle
Overview
Creating the mwrep User
Setting up SQL Translation Framework OBE for Database 12cR1
database to contain the migration repository. To create a new database user, perform the following steps:
Note:If you already have a noncdb_user connection and a mwrep user, you can skip these steps.
1. If you installed the SQL Developer icon on your desktop, click the icon to start your SQL Developer session. If you do not have the icon located on your desktop, find the
executable file (either named "sqldeveloper.exe" on Windows or "sqldeveloper.sh" on Linux), and run it.
2. Select View > Connections.
3. In the Connections tab, right-click Connections and select New Connection. A New / Select Database Connection window will appear.
4. The New / Select Database Connection dialog opens. Enter the connection details as follows and click Test.
5. Check for the status of the connection on the left-bottom side (above the Help button). It should read Success. To save the connection, click Save.
Then click Connect. Close the window.
6. The connection is saved and you can see it listed under Connections in the Connections navigator.
7. Expand noncdb_user.
Note: When a connection is opened, a SQL Worksheet is opened automatically. The SQL Worksheet allows you to execute SQL against the connection you just created.
11. Grant unlimited quota to USERS tablespaces to MWREP using the following command:
alter user mwrep quota unlimited on users ;
Note: It's a new privilege in 12c required to write to tablespaces.
To convert the Sybase database to Oracle, you need to create a repository to store the required repository tables and PL/SQL packages. To do this, perform the following steps:
Note: If you already have a mwrep_noncdb connection and a migration repository for it, you can skip these steps.
1. Before you create the repository, you need to create a connection to the mwrep user. In the Connections tab, right-click Connections and select New Connection.
A New / Select Database Connection window will appear.
Note: If this tab is not visible, select View > Connections.
2. The New / Select Database Connection dialog opens. Enter the connection details as follows and click Test.
Connection Name: mwrep_noncdb
User Name: mwrep
Password: <your_password> (Select Save Password)
Hostname: localhost
SID: <your_own_SID>
3. Check for the status of the connection on the left-bottom side (above the Help button). It should read Success.
To save the connection, click Save. Then click Connect. Close the window.
4. The connection is saved and you can see it listed under Connections in the Connections tab.
5. Right-click the mwrep_noncdb connection and select Migration Repository > Associate Migration Repository.
6. Check for the status of the connection on the left-bottom side (above the Help button). It should read Success.
A progress window appears. Click OK.
The procedure for creating and running the Offline Capture Scripts the Sybase database scripts has been completed for you and the files are available in the zip file provided in the
prerequisites. To load the Offline Capture Scripts captured Sybase database scripts into Oracle SQL Developer, perform the following steps:
Note: It is important that the password is saved with the connection, otherwise the installing of the SQL Translation Profile will not work.
2. The migration wizard appears and it will walk you through the steps to convert third party databases to Oracle. Click Next.
3. In step 2, you need to select a connection for the migration repository. Select the mwrep_noncdb connection, and click Next.
4. In step 3, you need to provide the Project details. A Project is a container for the migration entities. Provide a Name to the project, and specify the Output Directory. Click
2. Expand Migration and select Identifier Options. Make sure "Sybase: Is Quoted Identifier On" is not selected. This is because the Sybase pubs2 database recognizes
double quotes as String literals. If this is set incorrectly it can cause the conversion failure of procedures, triggers and views. Click OK.
To convert the captured model into the converted model, perform the following steps:
1. As part of the convert, you should first set the "Use all Oracle 12c features in Migration". Go to Tools->Preferences. Expand Migration and select Generation Options.
6. The Database Migration actions are completed successfully. A message dialog box appears. Click OK.
7. In the Migration Projects tab, expand Converted Database Objects. Expand pubs2 > dbo_pubs2 > Procedures. Here you will find a procedure "expectedToFail" that has
a red "x" icon against it. This is a failed procedure.
8. Select dbo_pubs2 tab. Select Conversion Issues. This will display a report of "Translation limitation" and "Errors".
An error represents the failure to convert an object. This generally only affects objects defined in T-SQL (Procedures, Triggers, Functions, and Views). These objects are available in
the Converted Model after the conversion, but they remain defined in Sybase T-SQL and have not been converted to Oracle PL/SQL. Generally an object fails to convert because a part
of the T-SQL is not recognized. Once this part of the T-SQL is identified, it can be worked around so that the majority of the translation can be performed automatically. Leaving only a
small section of T-SQL to manually translate. In this tutorial, the sample database has been seeded with one procedure that fails to convert. The following steps outline how to go
about identifying the issue and complete its conversion. The steps used here are the same for any type of conversion failure. To resolve the errors, perform the following steps:
1. Select the Converted Database Objects in the Migration Projects and expand dbo_pubs2.
10. Commenting out statements until the procedure translates will help you identify the problematic statement. In this case there is a new line between the bang and equals -
"where lower(title) != @title".
A quick solution would be to remove the space, but a more generic approach for all issues would be to comment out the clause with a TODO comment.
Then manually replace it once in Oracle. Workaround the issue and click Translate again. You can notice that the code has been successfully translated into PL/SQL
on the right side textbox.
11. Select the contents of the corrected expectedToFail procedure from the left side text box and copy it.
3. This step provides you the Target Database details. Select the mode as Offline. You can select to drop the target objects here. Note down the Generated Script Directory
location. Check Proceed to Summary Page. Click Next.
3. Now that your scripts have run successfully, you can create a connection for the dbo_pubs2 user. Right-click Connection and select New Connection.
4. The New / Select Database Connection dialog opens. Enter the connection details as follows and click Test.
Connection Name: dbo_pubs2_noncdb
User Name: dbo_pubs2
Password:<your_password> (Select Save Password)
Hostname: localhost
SID: <your_own_SID>
5. Check for the status of the connection on the left-bottom side (above the Help button). It should read Success. To save the connection, click Connect. Close the window.
8. The database tables that were converted to Oracle are listed. Select AUTHORS.
9. Select Data tab. Notice that currently there is no data in the table. You will migrate the data later in this OBE.
A date format mask can be specified in the preferences so that the Offline Data Move scripts (in particular, the Oracle SQL*Loader control files) can reference the correct format. To do
4. In the DBA Navigator, right-click Connections and select Add Connection.
5. In the Select Connection box, select the mwrep_noncdb connection and click OK. Again, repeat the same step and select dbo_pubs2_nondcb connection and click OK.
6. Grant the following privileges to the mwrep and dbo_pubs2 user using ADMIN privileges to allow the users to explicitly alter the session to use a profile.
7. Increase the size of the SGA (required to load the java into memory when invoking the translator.Select the noncdb_user connection and open a SQL worksheet Run the following commands using F5.
alter system set memory_max_target=1000M scope=spfile;
alter system set memory_target=1000M scope=spfile;
11. Along with installing the SQL Translator, the Install SQL Translator dialog box also enables you to create a translation profile by performing the following steps:
1. From the SQL Translator drop-down box, select Sybase SQL Translator.2. Check Create New Profile.
3. Enter Sybase_profile in Profile Name field.
4. In Profile Schema, select dbo_pubs2_noncdb.
5. Click Apply.
Note: Be sure to install the Profile into the same connection/schema as the dbo_pubs2 user.
12. Verify that the user has sufficient privileges to run the translation profile. When prompted, supply SYS password to grant LoadJava privileges to dbo_pubs2 user.
13. Install Translator.
14. Grant the following permission using the dbo_pubs2 user to the mwrep user to allow the translator to reference the Profile.
GRANT ALL ON SQL TRANSLATION PROFILE SYBASE_PROFILE TO MWREP;
15. Grant the following privileges using the and mwrep user to the dbo_pubs2 user to allow the profile to reference the Translator.
GRANT EXECUTE ON SYBASE_TSQL_TRANSLATOR TO DBO_PUBS2;
16. Close all connections at this point to ensure the privileges are granted.
17. To ensure that both the Profile and Translator are properly installed, verify whether the appropriate package and Java class files are present or not in the Connections
You can test the SQL Translation Profile by using SQL worksheet in the following way:
1. Right click on the SQL Translation Profile in the DBA tree and select Open SQL Worksheet with Profile.
2. Run some basic sybase queries. For example, SELECT 'A' + 'B';
3. You should get the results as follows:
SELECT 'A' || 'B' with AB → results
4. Open the SQL Translation Profile and confirm the contents of the SQL Translations Page.
This section shows you a Java application running Sybase SQL against Oracle. Perform the following steps to run the java application which converts a Sybase Java application to
1. Change the Sybase connection to connect to Oracle (using the Oracle JDBC driver and Oracle connection details).
Note: All the changes are already done for you. The below screenshot just shows you the changes made to this application.
2. Set the SQL Translator Profile for the Oracle connection.
3. Build and run the application.
4. The result is shown below:
In this tutorial, you have successfully migrated a Sybase ASE database to an Oracle 12c database, including the objects and data. You have also used the new SQL Translation
Framework to allow an existing Sybase ASE application to run against our new Oracle database without making any changes to the application SQL statements. Customers migrating
existing Sybase ASE and SQL Server databases and applications to Oracle Database 12c will greatly reduce time and effort in their migration projects.
Resources
Oracle Learning Library
Migrating a Sybase Database to Oracle Database 11g