Migration From Oracle To TD
Migration From Oracle To TD
Teradata
Data Warehouse
07 December 2015
Course (23280)
• Migration Options
• SQL Functions
• Stored Procedures
• Other Database Objects
• Misc. Migration Considerations
• Summary
2 © 2014
2
Migration Options
3 © 2014 Teradata
Migration Options
Availability Availability
Availability
Scalability Scalability
Scalability
Single View of the Single View of the
Business Business Single View of the
Business
4
SQL Functions
5 © 2014 Teradata
SQL Functions Comparison
6 © 2014
Functions Supported “AS IS”
7 © 2014
Functions having different equivalents in
Oracle Equivalent Teradata Function
Function
REPLACE OREPLACE
ADD_MONTHS OADD_MONTHS
CONCATENATE Concatenation Operator: a || b
TRANSLATE OTRANSLATE
SYSDATE CURRENT_DATE / CURRENT_TIMESTAMP
TO_NCHAR CAST
TO_LOB, TO_CLOB CAST
MOD(a, b) a MOD b
8 © 2014
Functions not supported in
Oracle Function
DENSE_RANK Only RANK supported in Teradata. Can be coded as UDF
LAG, LEAD Equivalent can be coded using ordered analytic functions in Teradata
NLS_INITCAP, NLS_UPPER, NLS_LOWER Use Oracle specific NLS (National Language Support) feature
ROWIDTOCHAR, ROWIDTONCHAR Use ROWID which is Oracle specific feature. Teradata internally
maintains ROWID but it is not “selectable” in SQL
SCN_TO_TIMESTAMP, TIMESTAMP_TO_SCN Use Oracle specific SCN (system change number) feature.
ORA_HASH Can be replaced with “Random sampling” queries / WIDTH_BUCKET in
Teradata
9 © 2014
User Defined Functions
Oracle UDF
Functions involving loops / complex
Option 2
Java / expressions, file handling
C
UDF
Written in PL/SQL.
Wrapper for most often used
computations / expressions Functions involving loops / complex
Complex UDFs (loops, Stored expressions, DML, DDL statements
complex calculations, DDL, Procedur
DML)
e
1 © 2014
User Defined Functions
• Oracle Table Functions
– Table functions are functions that produce a collection of rows (return a
“collection type” object)
– Table functions can be queried like a physical database table
– Oracle Table UDFs are coded using PL/SQL
1 © 2014
Stored Procedures
12 © 2014 Teradata
Stored Procedure
1 © 2014
Stored Procedures: Stored Procedure
Oracle Teradat
a
Declaration Declaration
Cursor and Variable Declaration
BEGIN BEGIN
Cursor and Variable Declarations
Exception Handlers
Procedure Code Procedure Code
Exception Handlers
END END
1 © 2014
Stored Procedures: Stored Procedure
Example: Example:
CREATE OR REPLACE PROCEDURE REPLACE PROCEDURE
{PROCEDURE_NAME}(<Parameters>) IS {PROCEDURE_NAME}(<Parameters>)
<Variable Declarations> BEGIN
BEGIN <Variable Declarations>
<Procedure body> <Exception Handlers>
EXCEPTION WHEN <Procedure body>
<Exception Handlers> END
END
1 © 2014
Stored Procedure Conversion : Procedure
• Procedure naming convention
– Oracle procedure names can be used as procedure name in Teradata in most
cases
– Procedure name in Teradata will need to be changed if
- Stored procedure name conflicts with Teradata reserved words.
Note: Stored procedure can be defined with same name as reserved word, but every reference to that SP needs to
be enclosed in double quotes
1 © 2014
Stored Procedure Conversion : Variable
1 © 2014
Stored Procedure Conversion : Exception
1 © 2014
Stored Procedure Conversion : Exception
1 © 2014
Stored Procedure Conversion : Transaction
2 © 2014
Stored Procedure Conversion – Other
• Stored procedure conversion should also consider
– Conversion of “row based” (cursor) code to “set based” code
– Conversion of recursive stored procedures
– File Handling
2 © 2014
Stored Procedure Conversion – Row based vs.
• “row based” (cursor) vs. “set based”
– Significant performance benefits can be obtained by converting Oracle “row
based” to set based procedures
– Row by row processing should be replaced with set based
processing wherever possible
2 © 2014
Stored Procedure Conversion: Recursive
2 © 2014
Stored Procedure Conversion: File
2 © 2014
Package
=
1 Oracle Package 1 Teradata Database
2 © 2014
Package
Oracle Package Component Teradata Equivalent
Package Specification • Package = Database
2 © 2014
Oracle Scripts
26 © 2014 Teradata
SQL*Plus Script
2 © 2014
SQL*Plus Scripts with Anonymous
– Naming of converted stored procedure should reflect original script in which the anonymous block appeared.
– All SQL*Plus variables used in anonymous blocks need to be passed as procedure parameters
– Treatment of variable in the PL/SQL block will determine whether the variable is declared as “IN” , “OUT” or
“INOUT” variable
– It might be necessary to convert the DML statements in anonymous block to dynamic SQL.
– Additional exception handling / propagation mechanisms may be required to ensure that correct success /
failure status is returned to the calling BTEQ script
– Other guidelines for anonymous PL/SQL are same as those for stored procedure conversion
2 © 2014
SQL*Loader
2 © 2014
Other Database Objects
30 © 2014 Teradata
External
Table
External Table Option 1 1. Small sized files
Function 2. Only “SELECT” access
TPT Script
External Table Option 2 1. Large files
2. SELECT from file
3. Data unload to file
3
DB
1. Table function using external stored procedure to
Table unload data from source DB
Oracle DB Link Option 1 Functions 2. Use for small volumes (data in MBs)
3. Can allow “on the fly” queries involving Table
functions
3
Synony
3 © 2014
Materialized Views –
Join Index
Materialized
View
3 © 2016
Materialized Views –
Permanent
Materialized
View Table + ETL
3 © 2016
Java and Perl Applications
• Java applications can run against Teradata by leveraging Teradata’s JDBC
Driver.
http://downloads.teradata.com/download/connectivity/jdbc -driver
• If application uses Hibernate, use SQL views
– Recommendation for Teradata is to create logical “tables” i.e. views that are
made available to Hibernate
– Let the view do the real SQL work
– Deliver all the data in one request
• Perl applications can run against Teradata by leveraging the DBI connector for
Teradata for PERL
– http://search.cpan.org/~darnold/DBD-Teradata-1.52/lib/DBD/Teradata.pm
3
Other Migration Considerations
37 © 2014 Teradata
Other considerations for Migration
3 © 2014
Summary
Successful Migrations are determined by:
3
40
4
0