This tutorial shows you how to migrate a Sybase database to Oracle Database 11g using Oracle SQL Developer.
Approximately 45 mins
This tutorial covers the following topics:
Place
the cursor over this icon to load and view all
the screenshots for this tutorial. (Caution: This action loads all
screenshots simultaneously, so response time may be slow depending on your Internet
connection.)
Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.
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.
Microsoft SQL Server Migration Overview
Using Oracle SQL Developer Migration Workbench, 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 your Sybase database. This can be done in two ways.
The second method is what you will perform in this tutorial. Using SQL Developers Offline Capture feature, Sybase Northwind sample database has been extracted into offline data files. The Sybase15.ocp file generated by the Capture contains the database schema information for the Sybase pubs2 database. Oracle SQL Developer Migration Workbench uses this file as the basis for building a representation of the structure of the source Microsoft Access database. This structure is called the Captured Model. |
| Convert the Captured Database | Oracle SQL Developer Migration Workbench 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 Database | Oracle SQL Developer Migration Workbench generates DDL statements to create the new Oracle database, based upon the Converted Model objects. Running the DDL statements will result in the creation of the objects in the Oracle database. |
| Migrate the Data |
The last step in the process is to migrate the data. You can do this in one of two ways.
The second method is what you will perform in this tutorial. |
In this tutorial, the required scripts for the offline migration have already been generated and modified.
This tutorial uses a modified version of the pubs2 sample database. This sample database has been seeded with migration issues, so that a more complex migration can be demonstrated.
The following issues will be covered.
If you are unfamiliar with SQL Developer Migration Workbench, please follow the "Migrating a Microsoft SQL Server Database to Oracle Database 11g" tutorial first.
Before you perform this tutorial, you should:
| 1. | Install the Oracle Database 10g or later, or Oracle Database XE |
|
| 2. | Download and unzip Oracle SQL Developer here. |
|
| 3. | Download and unzip the sybasemigration.zip file into your working directory (i.e.wkdir) |
|
To create a new database user, perform the following steps:
Note: If you already have a system_orcl connection and a mwrep user, you can skip these steps.
| 1. |
Open Oracle SQL Developer from the icon on your desktop.
|
|
| 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. |
Enter system_orcl in the Connection Name field (or any other name that identifies your connection), system for the Username field, and <your password> for the Password field. Select the Save Password check box. Enter <hostname> in the Hostname field and orcl in the SID field. 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 Connect. Close the window.
|
|
| 6. |
The connection is saved and you can see it listed under Connections in the Connections tab.
|
|
| 7. |
Expand the system_orcl connection. 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.
|
|
| 8. |
Enter the following code in the SQL Worksheet to create a user for the migration repository CREATE USER MWREP
IDENTIFIED BY mwrep
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP;
GRANT CONNECT, RESOURCE, CREATE SESSION, CREATE VIEW TO MWREP;
|
|
| 9. |
Run the script , using the "Run Script (F5)" icon.
|
|
| 10. |
The mwrep user was created successfully.
|
|
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_orcl 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. |
Enter mwrep_orcl in the Connection Name field (or any other name that identifies your connection), mwrep for the Username and Password fields. Select the Save Password check box. Enter <hostname> in the Hostname field and orcl in the SID field. Click Test.
|
| 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 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_orcl connection and select Migration Repository > Associate Migration Repository.
|
| 6. |
A progress window appears.
|
| 7. |
When the repository has been built, click Close.
|
| 8. |
Click OK.
|
The procedure for creating the Sybase database scripts has been completed for you and the files are available in the C:\hol08\migration\Sybase\files\Capture directory. To view this procedure, click here.
To load the captured Sybase database scripts into Oracle SQL Developer, perform the following steps:
| 1. |
Select Migration > Third Party Database Offline Capture > Load Database Capture Script Output.
|
| 2. |
Browse the Capture directory and select the sybase15.ocp file.
|
| 3. |
The objects are being captured. When done, click Close.
|
| 4. |
Sybase15 is listed in the Captured Models tab. Expand Sybase15.
|
| 5. |
Expand dbo to see the list of objects that were captured.
|
It is important to review the conversion preferences at this point. To do so, perform the following steps:
| 1. |
Select Tools > Preferences.
|
| 2. |
Expand Migration and select Identifier Options.
|
| 3. |
Make sure "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.
|
| 4. | From the Captured Model tab, expand Procedures and select storename_proc.
Notice the use of "%".
|
To convert the captured model to the Oracle model, perform the following steps:
| 1. |
Right-click the captured model Sybase15 and select Convert to Oracle Model.
|
| 2. |
The Set Data Map window appears, that shows you the Source Data Type and what it will be converted to in the Oracle Model. Click Apply.
|
| 3. |
The conversion is performed. When done, click Close.
|
| 4. |
Expand Converted:Sybase15 listed in the Converted Models tab.
|
| 5. |
Expand dbo_pubs2 to view the converted objects.
|
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:Sybase15 model in the Converted Model navigator and expand dbo_pubs2.
|
| 2. |
Expand Procedures and select expectedToFail. The Migration Log - Log tab contains the list of errors and warnings that occurred during the conversion.
|
| 3. |
Right-click the Failed To Convert Stored Procedure error and select View Details.
|
| 4. |
In this example, the error message provides line details to help identify the problematic syntax. Not all errors provide this information. For the purposes of this tutorial this information will be ignored, but during your own migration this information is helpful. Click OK.
|
| 5. |
You will now fix these errors. Copy the contents of the expectedToFail file and select Migration > Translation Scratch Editor.
|
| 6. |
Double-click Scratch Editor to enlarge the editor.
|
| 7. |
Adjust the two text boxes.
|
| 8. |
Paste the copied text from the expectedToFail file in the Enter 3rd Party SQL: text box.
|
| 9. |
Click the drop-down list and select Sybase T-SQL To PL/SQL.
|
| 10. |
Click the Translate icon.
|
| 11. |
You get an error as expected. Click OK.
|
| 12. |
Comment out statements and clauses of the DDL and retranslate until the problematic statement or clause is identified. If your having difficulty identifying the issue, watch this.
|
| 13. | You should have identified that the clause "where lower(title) !
= @title" was the issue.
The space between bang and equals was not recognized. 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.
|
| 14. |
Select the contents of the Generated PL/SQL: text box and copy it.
|
| 15. |
Double-click the Scratch Editor tab.
|
| 16. |
Click the expectedToFail file.
|
| 17. |
Click the Edit icon.
|
| 18. |
Paste the copied content in the new expectedToFail tab that opens.
|
| 19. |
Scroll down till the where clause you commented.
|
| 20. |
Resolve the TODO comment yourself. Remove the comments and change the where clause to: where lower(title) != v_title;
|
| 21. |
Click the Save button.
|
| 22. |
Objects that fail to convert are not automatically placed in the generation script. This stops unconverted T-SQL from being run against an Oracle database. For the expecteToFail procedure to be added to the generation script the preference must be set. Select Tools > Preferences.
|
| 23. |
Expand Migration and select Generation Options.
|
| 24. |
Select the Generate Failed Objects check box and click OK.
|
Limitations are produced during the conversion of objects defined using Sybase T-SQL (Procedures, Triggers, Views, and Functions). They provide information to the user about Sybase T-SQL syntax that you do not currently translate automatically. The majority of the Sybase T-SQL language is recognized and converted automatically, but there are certain syntax constructs that you have yet to define a translation for. This syntax is recognized during the conversion and a "Limitation" informational message is placed in the log. These limitations have to be reviewed to see if any manual modification is required. Some limitations identify constructs that have no meaning in Oracle, and can be ignored. Other limitations require manual effort to resolve.
The sample database used in this tutorial has one procedure expectLimitations where two limitations are present. To resolve these limitations , perform the following steps:
| 1. |
In the Migration Log - Log tab, double-click the Multiple Limitations... message.
|
| 2. | Double Click on the "Translation Limitation 'Set' encountered"
The converted procedure, expectLimitations, is opened at the line: /*TODO:SET QUOTED_IDENTIFIER
OFF*/
|
| 3. |
Click the Edit icon. A new expectLimitations tab opens.
|
| 4. |
This statement does not have an Oracle equivalent and its conversion
is not required. Remove the TODO comment. Click Save.
|
| 5. |
Double Click on the "Translation Limitation 'VALID_NAME' encountered" The converted procedure, expectLimitations, is opened at the line: SELECT VALID_NAME(v_identifierName)
|
| 6. |
Click the Edit icon.
|
| 7. |
VALID_NAME is a system function in Sybase. The conversion Limitation informs us that this function has not be automatically converted. The converter can decided how to best approach the migration of the VALID_NAME function. For the purposes of this tutorial, a function VALID_NAME will be created in the sybase_utilities package that can then be implemented. Add the text sybase_utilities. before VALID_NAME(v_identifierName).
|
| 8. |
Save the file. You will update the sybase_utilities package after it has been created in our Oracle database.
|
To generate the SQL script with DDL statements that will be
executed to create the objects in an Oracle Database,
perform the following steps:
| 1. |
Right-click Converted:Sybase15 and select Generate.
|
| 2. |
The Oracle SQL is being generated. When done, click Close.
|
| 3. |
The SQL from the script is shown. Select system_orcl from the drop-down on the right. icon.
|
| 4. |
Click the Run Script (F5).
|
| 5. |
The results are display from the script execution.
|
| 6. |
Now that your scripts have run successfully, you can create a connection for the dbo_pubs2 user. Right-click Connection and select New Connection.
|
| 7. |
Enter dbo_pubs2_orcl in the Connection Name field (or any other name that identifies your connection), dbo_pubs2 for the Username and Password fields. Select the Save Password check box. Enter <hostname> in the Hostname field and orcl in the SID field. Click Test.
|
| 8. |
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.
|
| 9. |
Expand the dbo_pubs2_orcl connection.
|
| 10. |
Expand Tables.
|
| 11. |
The database tables that were converted to Oracle are listed. Select the AUTHORS table.
|
| 12. |
Select the Data tab. Notice that currently there is no data in the table. You will migrate the data later in this tutorial.
|
The migration from Sybase to an Oracle database can be straightforward. But it is worth noting that some objects and syntax are not automatically migrated. Therefore manual intervention is required.
Analysing the Capture Model, identifying the number, type and complexity of objects , can help calculate the estimated time required for manual tasks.
The following Reports can be used with your own task and project estimation.
Estimate time to:
A Date Format Masks needs to be specified for Oracle to recognize the Sybase DATETIME and SMALLDATETIME values in the exported data files. A date format masks can be specified in the preferences so that the Offline Data Move scripts and in particular the Oracle SQL*Loader control files can reference the correct format. To do so, perform the following steps:
| 1. |
Select Tool > Preferences.
|
| 2. |
Expand Migration and select Data Move Options.
|
| 3. |
Change the Date Mask to the following. This will be used on Sybase SMALLDATETIME columns Mon dd yyyy HH:mi:ssAM
|
| 4. |
Change the Timestamp Mask to the following. This will be used on the Sybase DATETIME columns Mon dd yyyy HH:mi:ss:ff3AM Click OK.
Note: Although a TIMESTAMP may be used to recognize the Sybase DATETIME
values, this will get implicitly converted to a DATE if required during
the data load. |
The data has already been generated from the Sybase database. To view the steps, click here.
To import the data using the scripts provided, perform the
following steps:
| 1. |
Open a DOS command prompt and execute the following commands: <prompt> cd <location where files are> <prompt> oracle_ctl The files are located in the Data directory where you unzipped the files provided in the prerequisites section. oracle_ctl is a bat file that contains statements to load the data. It uses sqlldr to load the data.
|
| 2. |
The command executes successfully.
|
| 3. |
Switch to Oracle SQL Developer and Refresh the connection. The data for the table has been loaded successfully.
|
Browsing the converted database through the dbo_pubs2_migrated_orcl
connection you will notice that one procedure (expectedLimitation) has an invalid
icon. It has failed to compile as you have yet to resolve the VALID_NAME function.
As you are working in a real instance of an Oracle database, you can use SQL
Developer tools to their fullest to resolve such issues. To resolve the issue,
perform the following steps:
| 1. |
In the Connections navigator, expand the Procedures node and select EXPECTLIMITATIONS.
|
| 2. |
Right-click EXPECTLIMITATIONS and select Compile.
|
| 3. |
Some errors are displayed in the Compiler - Log tab. VALID_NAME is not yet defined. You have to manually create it.
|
| 4. |
Under Packages, double-click the Sybase_Utilities node. It opens in a separate tab.
|
| 5. |
Add the following function: FUNCTION valid_name(p_identifierName IN VARCHAR2) RETURN NUMBER;
|
| 6. |
Click the Compile icon.
|
| 7. |
Double-click the Sybase_Utilities Body node.
|
| 8. |
Click the Edit icon.
|
| 9. |
Add the following definition for the function: FUNCTION valid_name(p_identifierName
IN VARCHAR2)
|
| 10. |
Click the Compile icon.
|
| 11. |
Double-click the EXPECTLIMITATIONS tab.
|
| 12. |
Click the Compile icon. The procedure gets complied successfully.
|
During your testing of the migrated database, you may find issues. For example, the function sybase_utilities.valid_name has to be completed to be logically correct. Another issue that requires manual effort is the conversion of Dynamic SQL. T-SQL within the string literals is not converted automatically. All Dynamic SQL has to be verified and possibly converted manually. The below example is trivial to resolve manually, but for the purposes of this tutorial you will take a more general approach. Perform the following steps:
| 1. |
Under the Procedures node, select the DYNAMICSQL procedure.
|
| 2. |
The following T-SQL still resides within the converted procedure. The TOP n syntax is not valid in Oracle, so a conversion is required. EXECUTE IMMEDIATE 'SELECT TOP
10 ' || v_selectList || ' FROM ' || v_tableName || ' WHERE ' || v_condition;
|
| 3. |
Copy the select statement and open the Translation Scratch Editor (Migration > Translation Scratch Editor).
|
| 4. |
Select Sybase T-SQL To PL/SQL from the drop-down list.
|
| 5. |
Paste the copied text in the Enter 3rd Party SQL: text box.
|
| 6. |
Modify the statement to create a valid "dummy" T-SQL statement. This has to be valid Sybase T-SQL. You can use the text given below. Click the Translate icon. SELECT TOP 10 dummylist/* v_selectList*/
|
| 7. |
The resulting PL/SQL in shown on the right hand side window. This helps define what the Sybase T-SQL TOP n clause can be emulated in Oracle using a ROWNUM condition.
|
| 8. |
Using the above translation, recreate the Dynamic SQL as follows: ' SELECT '|| v_selectList ||
' FROM ' || v_tableName ||
' WHERE ' || v_condition ||
' AND ROWNUM <= 10';
|
| 9. |
Click the Edit icon in the DYNAMICSQL tab.
|
| 10. |
Replace the copied text. Note that as this is a dynamic query, and a result set needs to be passed back. See below for the completed procedure. After making the correct modification click the Compile icon.
|
| 11. |
The procedure gets complied successfully.
|
Depending on the complexity of the database being migrated, a large part of the migration project could be testing.
Currently Oracle does not provide any tools that can automatically validate a migrated database for you. This phase of the migration should be planned and taken into account before the migration begins.
The following should be part of your project plan
In this tutorial, you learned how to: