Oracle Migration Workbench Reference Guide for Microsoft SQL Server and Sybase Adaptive Server Migrations Release 9.2.0 for Microsoft Windows 98/2000 and Microsoft Windows NT Part Number A97248-01 |
|
This chapter contains information comparing the Microsoft SQL Server and Sybase Adaptive Server database and the Oracle database. It includes the following sections:
The schema contains the definitions of the tables, views, indexes, users, constraints, stored procedures, triggers, and other database-specific objects. Most relational databases work with similar objects.
The schema migration topics discussed here include the following:
There are many similarities between schema objects in Oracle and schema objects in Microsoft SQL Server and Sybase Adaptive Server. However, some schema objects differ between these databases, as shown in the following table:
Reserved words differ between Oracle and Microsoft SQL Server and Sybase Adaptive Server. Many Oracle reserved words are valid object or column names in Microsoft SQL Server and Sybase Adaptive Server. For example, DATE is a reserved word in Oracle, but it is not a reserved word in Microsoft SQL Server and Sybase Adaptive Server. Therefore, no column is allowed to have the name DATE in Oracle, but a column can be named DATE in Microsoft SQL Server and Sybase Adaptive Server. Use of reserved words as schema object names makes it impossible to use the same names across databases.
You should choose a schema object name that is unique by case and by at least one other characteristic, and ensure that the object name is not a reserved word from either database.
For a list of reserved words in Oracle, see the Oracle9i SQL Reference, Release 1 (9.0.1).
This section discusses the many table design issues that you need to consider when converting Microsoft SQL Server and Sybase Adaptive Server databases to Oracle. These issues are discussed under the following headings:
This section outlines conversion considerations for the following data types:
The date/time precision in Microsoft SQL Server and Sybase Adaptive Server is 1/300th of a second. Oracle9i has a new data type TIMESTAMP which has a
precision of 1/100000000th of a second. Oracle also has a DATE data type that stores date and time values accurate to one second. The Migration Workbench has a default mapping to the DATE data type.
For applications that require finer date/time precision than seconds, the TIMESTAMP data type should be selected for the datatype mapping of date data types in Microsoft SQL Server and Sybase Adaptive Server. The databases store point-in-time values for DATE and TIME data types.
As an alternative, if an Microsoft SQL Server and Sybase Adaptive Server application uses the DATETIME column to provide unique IDs instead of point-in-time values, replace the DATETIME column with a SEQUENCE in the Oracle schema definition.
In the following examples, the original design does not allow the DATETIME precision to exceed seconds in the Oracle table. This example assumes that the DATETIME column is used to provide unique IDs. If millisecond precision is not required, the table design outlined in the following example is sufficient:
Original Table Design
Microsoft SQL Server and Sybase Adaptive Server:
CREATE TABLE example_table (datetime_column datetime not null, text_column text null, varchar_column varchar(10) null)
Oracle:
CREATE TABLE example_table (datetime_column date not null, text_column long null, varchar_column varchar2(10) null)
The following design allows the value of the sequence to be inserted into the integer_column. This allows you to order the rows in the table beyond the allowed precision of one second for DATE data type fields in Oracle. If you include this column in the Microsoft SQL Server and Sybase Adaptive Server table, you can keep the same table design for the Oracle database.
Revised Table Design
Microsoft SQL Server and Sybase Adaptive Server:
CREATE TABLE example_table (datetime_column datetime not null, integer_column int null, text_column text null, varchar_column varchar(10) null)
Oracle:
CREATE TABLE example_table (datetime_column date not null, integer_column number null, text_column long null, varchar_column varchar2(10) null)
For the Microsoft SQL Server and Sybase Adaptive Server database, the value in the integer_column is always NULL. For Oracle, the value for the field integer_column is updated with the next value of the sequence.
Create the sequence by issuing the following command:
CREATE SEQUENCE datetime_seq
Values generated for this sequence start at 1 and are incremented by 1.
Many applications do not use DATETIME values as UNIQUE IDs, but still require the date/time precision to be higher than secondS. For example, the timestamp of a scientific application may have to be expressed in milliseconds, microseconds, and nanoseconds. The precision of the Microsoft SQL Server and Sybase Adaptive Server DATETIME data type is 1/300th of a second; the precision of the Oracle DATE data type is one second. The Oracle TIMESTAMP data type has a precision to 1/100000000th of a second. However, the precision recorded is dependent on the operating system.
The physical and logical storage methods for IMAGE
and TEXT
data differ from Oracle to Microsoft SQL Server and Sybase Adaptive Server. In Microsoft SQL Server and Sybase Adaptive Server, a pointer to the IMAGE
or TEXT data is stored with the rows in the table while the IMAGE
or TEXT
data is stored separately. This arrangement allows multiple columns of IMAGE
or TEXT
data per table. In Oracle, IMAGE data may be stored in a BLOB
type field and TEXT
data may be stored in a CLOB
type field. Oracle allows multiple BLOB
and CLOB
columns per table. BLOBS
and CLOBS
may or may not be stored in the row depending on their size.
If the Microsoft SQL Server and Sybase Adaptive Server TEXT
column is such that the data never exceeds 4000 bytes, convert the column to an Oracle VARCHAR2 data type column instead of a CLOB
column. An Oracle table can define multiple VARCHAR2
columns. This size of TEXT
data is suitable for most applications.
This Microsoft SQL Server and Sybase Adaptive Server T-SQL-specific enhancement to SQL allows users to define and name their own data types to supplement the system data types. A user-defined data type can be used as the data type for any column in the database. Defaults and rules (check constraints) can be bound to these user-defined data types, which are applied automatically to the individual columns of these user-defined data types.
While migrating to Oracle PL/SQL, you must determine the base data type for each user-defined data type, to find the equivalent PL/SQL data type.
Note: User-defined data types make the data definition language code and procedural SQL code less portable across different database servers. |
You can define a primary key for a table in Microsoft SQL Server and Sybase Adaptive Server. Primary keys can be defined in a CREATE TABLE
statement or an ALTER TABLE
statement.
Oracle provides declarative referential integrity. A primary key can be defined as part of a CREATE TABLE
or an ALTER TABLE
statement. Oracle internally creates a unique index to enforce the integrity.
You can define a foreign key for a table in Microsoft SQL Server and Sybase Adaptive Server. Foreign keys can be defined in a CREATE TABLE
statement or an ALTER TABLE
statement.
Oracle provides declarative referential integrity. A CREATE TABLE
or ALTER TABLE
statement can add foreign keys to the table definition. For information about referential integrity constraints, see the Oracle9i Database Concepts, Release 1 (9.0.1).
You can define a unique key for a table in Microsoft SQL Server and Sybase Adaptive Server. Unique keys can be defined in a CREATE TABLE statement or an ALTER TABLE statement.
Oracle defines unique keys as part of CREATE TABLE or ALTER TABLE statements. Oracle internally creates unique indexes to enforce these constraints.
Unique keys map one-to-one from Microsoft SQL Server and Sybase Adaptive Server to Oracle.
Check constraints can be defined in a CREATE TABLE statement or an ALTER TABLE statement in Microsoft SQL Server and Sybase Adaptive Server. Multiple check constraints can be defined on a table. A table-level check constraint can reference any column in the constrained table. A column can have only one check constraint. A column-level check constraint can reference only the constrained column. These check constraints support complex regular expressions.
Oracle defines check constraints as part of the CREATE TABLE or ALTER TABLE statements. A check constraint is defined at the TABLE level and not at the COLUMN level. Therefore, it can reference any column in the table. Oracle, however, does not support complex regular expressions.
create rule phone_rule as @phone_number like "([0-9][0-9][0-9])[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]"
This rule passes all the phone numbers that resemble the following:
(650)506-7000
This rule failes all the phone numbers that resemble the following:
650-506-7000
650-GET-HELP
There are a few ways to implement this INTEGRITY constraint in Oracle:
Table-level check constraints from Microsoft SQL Server and Sybase Adaptive Server databases map one-to-one with Oracle check constraints. You can implement the column-level check constraints from the Microsoft SQL Server and Sybase Adaptive Server database to Oracle table-level check constraints. While converting the regular expressions, convert all simple regular expressions to check constraints in Oracle. Microsoft SQL Server and Sybase Adaptive Server check constraints with complex regular expressions can be either reworked as check constraints including a combination of simple regular expressions, or you can write Oracle database triggers to achieve the same functionality.
This chapter provides detailed descriptions of the differences in data types used by Microsoft SQL Server and Sybase Adaptive Server and Oracle databases. Specifically, this chapter contains the following information:
TEXT and IMAGE data types in Microsoft SQL Server and Sybase Adaptive Server follow the rules listed below:
In Microsoft SQL Server and Sybase Adaptive Server only columns with variable-length data types can store NULL values. When you create a column that allows NULLs with a fixed-length data type, the column is automatically converted to a system variable-length data type, as illustrated in Table 2-3. These variable-length data types are reserved system data types, and users cannot use them to create columns
Note: The Oracle Migration Workbench Source Model will display table system data types for each column. |
Recommendations
In addition to the data types listed in Table 2-2, users can define their own data types in Microsoft SQL Server and Sybase Adaptive Server databases. These user-defined data types translate to the base data types that are provided by the server. They do not allow users to store additional types of data, but can be useful in implementing standard data types for an entire application.
You can map data types from Microsoft SQL Server and Sybase Adaptive Server to Oracle with the equivalent data types listed in the above table. The Migration Workbench converts user-defined data types to their base type. You can defined how the base type is mapped to an Oracle type in the Data Type Mappings page in the Options dialog.
This section provides a detailed description of the conceptual differences in data storage for the Microsoft SQL Server and Sybase Adaptive Server and Oracle databases.
Specifically, it contains the following information:
Recommendations:
The conceptual differences in the storage structures do not affect the conversion process directly. However, the physical storage structures need to be in place before conversion of the database begins.
Oracle, Microsoft SQL Server and Sybase Adaptive Server all have a way to control the physical placement of a database object. In Microsoft SQL Server and Sybase Adaptive Server, you use the ON SEGMENT clause and in Oracle you use the TABLESPACE clause.
An attempt should be made to preserve as much of the storage information as possible when converting from Microsoft SQL Server and Sybase Adaptive Server to Oracle. The decisions that were made when defining the storage of the database objects for Microsoft SQL Server and Sybase Adaptive Server should also apply for Oracle. Especially important are initial object sizes and physical object placement.
This section uses tables to compare the syntax and description of Data Manipulation Language (DML) elements in the Microsoft SQL Server and Sybase Adaptive Server, and Oracle databases. Each table is followed by a recommendations section based on the information in the tables. The following topics are presented in this section:
The statement illustrated in the following table connects a user to a database.
Recommendations:
This concept of connecting to a database is conceptually different in the Microsoft SQL Server and Sybase Adaptive Server, and Oracle databases. An Microsoft SQL Server and Sybase Adaptive Server user can log on to the server and switch to another database residing on the server, provided the user has privileges to access that database. An Oracle Server controls only one database, so here the concept of a user switching databases on a server does not exist. Instead, in Oracle a user executes the SET ROLE command to change roles or re-issues a CONNECT command using a different user_name.
The statement in the following table retrieves rows from one or more tables or views.
Microsoft SQL Server and Sybase Adaptive Server support SELECT statements that do not have a FROM clause. This can be seen in the following example
SELECT getdate()
Oracle does not support SELECTs without FROM clauses. However, Oracle provides the DUAL table which always contains one row. Use the DUAL table to convert constructs such as the one above.
Translate the above query to:
SELECT sysdate FROM dual;
The Microsoft SQL Server and Sybase Adaptive Server SELECT INTO statement can insert rows into a table. This construct, which is part SELECT and part INSERT, is not supported by ANSI. Replace these statements with INSERT...SELECT statements in Oracle.
If the Microsoft SQL Server and Sybase Adaptive Server construct is similar to the following:
SELECT col1, col2, col3 INTO target_table FROM source_table WHERE where_clause
you should convert it to the following for Oracle:
INSERT into target_table SELECT col1, col2, col3 FROM source_table WHERE where_clause
In Microsoft SQL Server and Sybase Adaptive Server, a SELECT statement may appear anywhere that a column specification appears. Oracle does not support this non-ANSI extension to ANSI SQL. Change the subquery in the SELECT list either by using a DECODE statement or by dividing the query into two different queries.
Use the following sales table as a basis for the examples below:
Year | Quantity | Amount |
1993 |
1 |
1.3 |
1993 |
2 |
1.4 |
1993 |
3 |
3 |
1993 |
4 |
2.3 |
If you want to select the year, q1 amount, q2 amount, q3 amount, and q4 as a row, Microsoft SQL Server and Sybase Adaptive Server accept the following query:
SELECT distinct year, q1 = (SELECT amt FROM sales WHERE qtr=1 AND year = s.year), q2 = (SELECT amt FROM sales WHERE qtr=2 AND year = s.year), q3 = (SELECT amt FROM sales WHERE qtr=3 AND year = s.year), q4 = (SELECT amt FROM sales WHERE qtr=4 AND year = s.year) FROM sales s
In this example, replace the SELECT statements with DECODE so that the query functions as normal. The DECODE function is much faster than Microsoft SQL Server and Sybase Adaptive Server subqueries. Translate the above query to the following for Oracle:
SELECT year, DECODE( qtr, 1, amt, 0 ) q1, DECODE( qtr, 2, amt, 0 ) q2, DECODE( qtr, 3, amt, 0 ) q3, DECODE( qtr, 4, amt, 0 ) q4 FROM sales s;
If you cannot convert the query using the above method, create views and base the query on the views rather than on the original tables.
For example, consider the following query in Microsoft SQL Server and Sybase Adaptive Server:
SELECT name, sumlength = (SELECT sum(length) FROM syscolumns WHERE id = t.id), count_indexes = (SELECT count(*) FROM sysindexes WHERE id = t.id) FROM sysobjects t
This query returns the sum of the lengths of the columns of a table and the number of indexes on that table. This is best handled in Oracle by using some views.
Convert this to the following in Oracle:
CREATE view V1 ( sumlength, oid ) as SELECT sum(length), id FROM syscolumns GROUP BY id CREATE view V2 ( count_indexes, oid ) AS SELECT count(*), id FROM sysindexes GROUP BY id SELECT name, sumlength, count_indexes FROM sysobjects t, v1, v2 WHERE t.id = v1.oid AND t.id = v2.oid
Microsoft SQL Server and Sybase Adaptive Server also allow a SELECT statement in the WHERE clause. For example, consider the following statement from Microsoft SQL Server and Sybase Adaptive Server:
SELECT empname, deptname FROM emp, dept WHERE emp.empno = 100 AND(SELECT security_code FROM employee_security WHERE empno = emp.empno) = (SELECT security_code FROM security_master WHERE sec_level = dept.sec_level)
Convert this to the ANSI-standard statement below for Oracle:
SELECT empname, deptname FROM emp, dept WHERE emp.empno = 100 AND EXISTS (SELECT security_code FROM employee_security es WHERE es.empno = emp.empno AND es.security_code = (SELECT security_code FROM security_master WHERE sec_level = dept.sec_level));
Convert column aliases from the following Microsoft SQL Server and Sybase Adaptive Server syntax:
SELECT employees=col1 FROM tab1e
to the following Oracle syntax:
SELECT col1 employees FROM tab1e
Remove table aliases (also known as correlation names) unless they are used everywhere.
Replace the COMPUTE
clause with another SELECT
. Attach the two sets of results using the UNION
clause.
Convert the outer JOIN
syntax from the Microsoft SQL Server and Sybase Adaptive Server syntax to the Oracle syntax.
In addition to these, there are many implications due to the differences in the implementation of the special clauses such as GROUP BY, functions, joins. These are discussed later in this chapter.
Table 2-7 compares the SELECT with GROUP BY
statement in Oracle to the same statement in Microsoft SQL Server and Sybase Adaptive Server.
The statements illustrated in the following table add one or more rows to the table or view.
Recommendations:
INSERT statements in Microsoft SQL Server and Sybase Adaptive Server must be changed to include an INTO clause if it is not specified in the original statement.
The values supplied in the VALUES clause in either database may contain functions. The Microsoft SQL Server-specific functions must be replaced with the equivalent Oracle constructs.
Note: Oracle lets you create functions that directly match most Microsoft SQL Server and Sybase Adaptive Server functions. |
Convert inserts that are inserting into multi-table views in Microsoft SQL Server and Sybase Adaptive Server to insert directly into the underlying tables in Oracle.
The statement illustrated in the following table updates the data in a table or the data in a table referenced by a view.
Recommendations:
There are two ways to convert UPDATE statements with FROM clauses as indicated below.
Use the subquery in the SET clause if columns are being updated to values coming from a different table.
Convert the following in Microsoft SQL Server and Sybase Adaptive Server:
update titles SET pub_id = publishers.pub_id FROM titles, publishers WHERE titles.title LIKE 'C%' AND publishers.pub_name = 'new age'
to the following in Oracle:
UPDATE titles SET pub_id = ( SELECT a.pub_id FROM publishers a WHERE publishers.pub_name = 'new age' ) WHERE titles.title like 'C%'
Use the subquery in the WHERE clause for all other UPDATE...FROM statements.
Convert the following in Microsoft SQL Server and Sybase Adaptive Server:
UPDATE shipping_parts SET qty = 0 FROM shipping_parts sp, suppliers s WHERE sp.supplier_num = s.supplier_num AND s.location = "USA"
to the following in Oracle:
UPDATE shipping_parts SET qty = 0 WHERE supplier_num IN ( SELECT supplier_num FROM suppliers WHERE location = 'USA')
The statement illustrated in the following table removes rows from tables and rows from tables referenced in views.
Remove the second FROM clause from the DELETE statements.
Convert the following Microsoft SQL Server and Sybase Adaptive Server query:
DELETE FROM sales FROM sales, titles WHERE sales.title_id = titles.title_id AND titles.type = 'business'
to the following in Oracle:
DELETE FROM sales WHERE title_id in ( SELECT title_id FROM titles WHERE type = 'business' )
Remove the second FROM even if the WHERE contains a multi-column JOIN.
Convert the following Microsoft SQL Server and Sybase Adaptive Server query:
DELETE FROM sales FROM sales, table_x WHERE sales.a = table_x.a AND sales.b = table_x.b AND table_x.c = 'd'
to the following in Oracle:
DELETE FROM sales WHERE ( a, b ) in ( SELECT a, b FROM table_x WHERE c = 'd' )
The following table compares the operators used in the Microsoft SQL Server and Sybase Adaptive Server, and Oracle databases. Comparison operators are used in WHERE clauses and COLUMN check constraints/rules to compare values
Recommendations:
Convert the following in Microsoft SQL Server and Sybase Adaptive Server:
WHERE col1 !< 100
to this for Oracle:
WHERE col1 >= 100
SELECT title FROM titles WHERE title like "[A-F]%"
Method 1 - Eliminating use of [ ]:
Use this method with the SUBSTR () function if possible.
SELECT title from titles where substr (titles,1,1) in ('A', 'B', 'C', 'D', 'E', 'F')
Method 2 - Eliminating use of [ ]:
The second method uses the % construct.
SELECT title FROM titles WHERE (title like 'A%' OR title like 'B%' OR title like 'C%' OR title like 'D%' OR title like 'E%' OR title like 'F%')
The following table shows that in Oracle, NULL is never equal to NULL. Change the all = NULL constructs to IS NULL to retain the same functionality.
If you have the following in Microsoft SQL Server and Sybase Adaptive Server:
WHERE col1 = NULL
Convert it as follows for Oracle:
WHERE col1 IS NULL
Operator | Same in All Three Databases | Microsoft SQL Server and Sybase Adaptive Server Only | Oracle Only |
---|---|---|---|
Add |
+ |
||
Subtract |
- |
||
Multiply |
* |
||
Divide |
/ |
||
Modulo |
v |
% |
mod(x, y) |
Recommendations:
Replace any Modulo functions in Microsoft SQL Server and Sybase Adaptive Server with the mod() function in Oracle.
Operator | Same in All Three Databases | Microsoft SQL Server and Sybase Adaptive Server Only | Oracle Only |
---|---|---|---|
Concatenate |
s |
+ |
|| |
Identify Literal |
'this is a string' |
"this is also a string" |
Recommendations:
Replace all addition of strings with the || construct.
Replace all double quotes string identifiers with single quote identifiers.
In Microsoft SQL Server and Sybase Adaptive Server, an empty string ('') is interpreted as a single space in INSERT or assignment statements on VARCHAR data. In concatenating VARCHAR, CHAR, or TEXT data, the empty string is interpreted as a single space. The empty string is never evaluated as NULL. You must bear this in mind when converting the application.
Operator | Same in All Three Databases | Microsoft SQL Server and Sybase Adaptive Server Only | Oracle Only |
---|---|---|---|
bit and |
& |
||
bit or |
| |
||
bit exclusive or |
^ |
||
bit not |
~ |
Recommendations:
Oracle enables you to write the procedures to perform bitwise operations.
If you have the following Microsoft SQL Server and Sybase Adaptive Server construct:
X | Y :(Bitwise OR)
You could write a procedure called dbms_bits.or (x,y) and convert the above construct to the following in Oracle:
dbms_bits.or(x,y)
Oracle adds the ability to define functions. With this feature you can create Oracle functions that match the name and function of Microsoft SQL Server and Sybase Adaptive Server functions.
Recommendations:
The above table lists all the Microsoft SQL Server and Sybase Adaptive Server date manipulation functions. It does not list all the Oracle date functions. There are many more Oracle date manipulation functions that you can use.
It is recommended that you convert most date manipulation functions to "+" or "-" in Oracle.
Oracle adds the ability to define functions. With this feature you can create Oracle functions that match the name and functionality of all Microsoft SQL Server and Sybase Adaptive Server functions. This is a useful feature, where users can call a PL/SQL function from a SQL statement's SELECT LIST, WHERE clause, ORDER BY clause, and HAVING clause. With the parallel query option, Oracle executes the PL/SQL function in parallel with the SQL statement. Hence, users create parallel logic.
Recommendations:
The above table lists all the Microsoft SQL Server and Sybase Adaptive Server number manipulation functions. It does not list all the Oracle mathematical functions. There are many more Oracle number manipulation functions that you can use.
Oracle adds the ability to define functions. With this feature you can create Oracle functions that match the name and functionality of all Microsoft SQL Server and Sybase Adaptive Server functions. This is the most flexible approach. Users can write their own functions and execute them seamlessly from a SQL statement.
Oracle functions listed in the table work in SQL as well as PL/SQL.
Locking serves as a control mechanism for concurrency. Locking is a necessity in a multi-user environment because more than one user at a time may be working with the same data.
Recommendations:
In Microsoft SQL Server and Sybase Adaptive Server, SELECT statements obtain shared locks on pages/rows. This prevents other statements from obtaining an exclusive lock on those pages/rows. All statements that update the data need an exclusive lock. This means that the SELECT statement in Microsoft SQL Server and Sybase Adaptive Server blocks the UPDATE statements as long as the transaction that includes the SELECT statement does not commit or rollback. This also means that two transactions are physically serialized whenever one transaction selects the data and the other transaction wants to change the data first and then select the data again. In Oracle, however, SELECT statements do not block UPDATE statements, since the rollback segments are used to store the changed data before it is updated in the actual tables. Also, the reader of the data is never blocked in Oracle. This allows Oracle transactions to be executed simultaneously.
If Microsoft SQL Server and Sybase Adaptive Server logical transactions are automatically translated to Oracle logical transactions, the transactions explained above that execute properly in Microsoft SQL Server and Sybase Adaptive Server as they are serialized causes a deadlock in Oracle. These transactions should be identified and serialized to avoid the deadlock. These transactions are serialized in Microsoft SQL Server and Sybase Adaptive Server as INSERT, UPDATE, and DELETE statements block other statements.
Recommendations:
No changes are required to take advantage of the row-level locking feature of Oracle.
Recommendations:
Transactions are not implicit in Microsoft SQL Server and Sybase Adaptive Server. Therefore, applications expect that every statement they issue is automatically committed it is executed.
Oracle transactions are always implicit, which means that individual statements are not committed automatically. When converting an Microsoft SQL Server and Sybase Adaptive Server application to an Oracle application, care needs to be taken to determine what constitutes a transaction in that application. In general, a COMMIT work statement needs to be issued after every "batch" of statements, single statement, or stored procedure call to replicate the behavior of Microsoft SQL Server and Sybase Adaptive Server for the application.
In Microsoft SQL Server and Sybase Adaptive Server, transactions may also be explicitly begun by a client application by issuing a BEGIN TRAN statement during the conversion process.
|
Copyright © 1998, 2002 Oracle Corporation. All Rights Reserved. |
|