Migration From Oracle To TD
Migration From Oracle To TD
Data Warehouse
07 December 2015
Course (23280)
• Migration Options
• SQL Functions
• Stored Procedures
• Other Database Objects
• Misc. Migration Considerations
• Summary
2
2 © 2014 Teradata
Migration Options
3 © 2014 Teradata
Migration Options
Availability Availability
Availability
Scalability Scalability
Scalability
Single View of the Single View of the
Single View of the
Business Business
Business
4
SQL Functions
5 © 2014 Teradata
SQL Functions Comparison
6 © 2014 Teradata
Functions Supported “AS IS”
7 © 2014 Teradata
Functions having different equivalents in Teradata
8 © 2014 Teradata
Functions not supported in Teradata
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 Teradata
User Defined Functions (UDF)
Written in PL/SQL.
Wrapper for most often used
computations / expressions Functions involving loops / complex
Stored
Complex UDFs (loops, complex expressions, DML, DDL statements
calculations, DDL, DML) Procedure
10 © 2014 Teradata
User Defined Functions (UDF)
• 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
11 © 2014 Teradata
Stored Procedures
12 © 2014 Teradata
Stored Procedure Conversion
13 © 2014 Teradata
Stored Procedures: Stored Procedure Constructs
Oracle Teradata
Declaration Declaration
Cursor and Variable Declaration
BEGIN BEGIN
Cursor and Variable Declarations
Exception Handlers
Procedure Code Procedure Code
Exception Handlers
END END
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
14 © 2014 Teradata
Stored Procedure Conversion : Procedure Naming
• 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
15 © 2014 Teradata
Stored Procedure Conversion : Variable Declarations
16 © 2014 Teradata
Stored Procedure Conversion : Exception Handling
17 © 2014 Teradata
Stored Procedure Conversion : Exception Handling
18 © 2014 Teradata
Stored Procedure Conversion : Transaction Handling
19 © 2014 Teradata
Stored Procedure Conversion – Other considerations
20 © 2014 Teradata
Stored Procedure Conversion – Row based vs. Set based
• “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
22 © 2014 Teradata
Stored Procedure Conversion: File Handling
23 © 2014 Teradata
Package Conversion
1 Oracle
Package
=
• Teradata does not have the concept of packages.
1 Teradata
Database
25 © 2014 Teradata
Oracle Scripts
26 © 2014 Teradata
SQL*Plus Script Conversion
SQL*Plus Script
Shell / PERL
Scripts + BTEQ Script + 1 Stored Proc.
per Anonymous
PL/SQL Block
– 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
28 © 2014 Teradata
SQL*Loader Scripts
SQL*Loader
Script
Pre-
processing + TPT Script
script
• Similarities between SQL*Loader and TPT
– Supports fast loading of delimited or fixed width text file and binary files
– Can load data to an empty or pre-populated table
– Can perform some amount of derivations during loading (e.g. calculated columns)
– Error logging and isolation of error records
30 © 2014 Teradata
External Tables
1. Large files
Option 2
External Table TPT Script 2. SELECT from file
3. Data unload to file
31
DB Links
1. Table function using external stored procedure to
unload data from source DB
Option 1 Table 2. Use for small volumes (data in MBs)
Oracle DB Link
Functions 3. Can allow “on the fly” queries involving Table
functions
32
Synonyms
33 © 2014 Teradata
Materialized Views – Option 1
Materialized
View Join Index
34 © 2016 Teradata
Materialized Views – Option 2
Materialized Permanent
View Table + ETL
35 © 2016 Teradata
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
36
Other Migration Considerations
37 © 2014 Teradata
Other considerations for Migration
38 © 2014 Teradata
Summary
Successful Migrations are determined by:
39
40
40