0% found this document useful (0 votes)
39 views

Migration From Oracle To TD

Uploaded by

imusmanahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Migration From Oracle To TD

Uploaded by

imusmanahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

​Migrating Oracle Applications and databases to the Teradata

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

1:1 Migration Integration Evolution

Performance Performance Performance

Availability Availability
Availability
Scalability Scalability
Scalability
Single View of the Single View of the
Single View of the
Business Business
Business

Business Questions Business Questions Business Questions


(Complexity) (Complexity) (Complexity)

Cost of Ownership Cost of Ownership Cost of Ownership


© 2014 Teradata

4
SQL Functions

5 © 2014 Teradata
SQL Functions Comparison

• Majority of Oracle functions are supported “As-Is” on Teradata


• Some Oracle built-in functions are supported but have different function
name in Teradata
• Functions that utilize / perform Oracle database specific features are not
supported (e.g.: ROWIDTOCHAR, TIMESTAMP_TO_SCN)
• User Defined functions capabilities of Oracle can be supported using
Teradata Features like
– SQL UDF
– C / Java UDF
– Stored Procedures

6 © 2014 Teradata
Functions Supported “AS IS”

Numeric Character Functions Date / Time Functions Aggregate / Other Functions


Functions Analytic Functions
ABS ASCII CURRENT_DATE SUM NVL
CEIL, CEILING CHR CURRENT_TIMESTAMP MIN, MAX NULLIF
FLOOR Concatenation: a || b LAST_DAY AVG COALESCE
ROUND INITCAP MONTHS_BETWEEN COUNT CAST
EXP, POWER INSTR TO_CHAR(DateTime) RANK DECODE
LN, LOG LENGTH TO_DATE STDDEV_POP TO_CHAR
SIN, SINH, COS, UPPER, LOWER TO_TIMESTAMP STDDEV_SAMP
COSH, TAN, TANH
SQRT LPAD, RPAD TRUNC REGR_AVGX,
REGR_AVGY
SIGN LTRIM, TRIM REGR_COUNT

TRUNC SUBSTR REGR_R2


TO_NUMBER TO_CHAR REGR_SLOPE
REGR_SXX,
REGR_SXY,
REGR_SYY

7 © 2014 Teradata
Functions having different equivalents in Teradata

Oracle Function Equivalent Teradata 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 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)

Expressions that can be coded using


standard SQL operators and
SQL UDF functions and result in a single value
output

Functions involving loops / complex


Oracle UDF Option 2
Java / C
expressions, file handling
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

• Teradata Table Functions


– Teradata supports Table Functions
– Table UDFs are external UDFs written in C / Java
– Table UDFs return a “table” object containing fixed number of columns.

11 © 2014 Teradata
Stored Procedures

12 © 2014 Teradata
Stored Procedure Conversion

Oracle Stored Teradata


Procedure Stored
Procedure

• Stored procedure conversion primarily involves converting


– Stored Procedure Construct
– Procedure Naming
– Variable Declarations
– Exception Handling
– Transaction semantics

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

- Stored procedure is overloaded in Oracle. Teradata does not support procedure


overloading
Note: Overloading is possible only for package stored procedures or procedure local to a PL/SQL block

15 © 2014 Teradata
Stored Procedure Conversion : Variable Declarations

Feature Oracle Teradata

Variable Declaration var_name DATATYPE [ := DECLARE var_name DATATYPE [


default_value] DEFAULT default_value]
%TYPE variables var_name TABLE.COLUMN%TYPE [ := Does not support this syntax. Variable
default_value] must be declared with explicitly chosen
data type
%ROWTYPE variables var_name TABLENAME%ROWTYPE ; Does not support this syntax. Options:
-- represents a structure that contains 1. Declare multiple variables
all columns from table TABLENAME. 2. User defined types
Arrays TYPE type_name IS TABLE OF Does not support this syntax. Options
element_type INDEX BY 1. VARRAY data type
2. Volatile / Temporary tables
BINARY_INTEGER | PLS_INTEGER;
var_name type_name ;

Assigning Value to var_name := var_value ; SET var_name = var_value ;


Variable

16 © 2014 Teradata
Stored Procedure Conversion : Exception Handling

Feature Oracle Teradata

Exception Declaration EXCEPTION WHEN DECLARE EXIT|CONTINUE HANDLER


<Exception_Name> THEN FOR <Exception_Name>
<PL/SQL code for exception> BEGIN
END <PL/SQL code for exception>
END
Note: Same as “EXIT HANDLER”s in
Teradata
User Defined Exception Exception_Name EXCEPTION ; DECLARE Exception_Name CONDITION
Declaration ;
Mapping user defined user_role_not_exists EXCEPTION DECLARE user_role_not_exists
exception to a Database ; CONDITION FOR SQLSTATE VALUE
defined error number pragma exception_init ‘52004’;
(user_role_not_exists, -1917) ;

17 © 2014 Teradata
Stored Procedure Conversion : Exception Handling

Feature Oracle Teradata

Raising Exceptions RAISE <Exception_Name> SIGNAL <Exception_Name>

Raise Exceptions with raise_application_error(- SIGNAL SQLSTATE VALUE ‘T7665’


custom message 20001, ‘Procedure failed with SET MESSAGE_TEXT = ‘Message’ ;
error ORA-' ||
LPAD(ABS(SQLCODE), 5, 0));
Exception related SQLCODE SQLCODE
Functions / Variables SQLERRM DIAGNOSTICS Area
• Contains MESSAGE_TEXT
(equivalent of SQLERRM)
Commonly Used NO_DATA_FOUND NOT FOUND
Exceptions
OTHERS SQLEXCEPTION

18 © 2014 Teradata
Stored Procedure Conversion : Transaction Handling

Transaction Features Oracle Teradata


Handling Feature Supported? Supported?
ANSI Semantics • Implicit transaction start Yes (Default) Yes
• Explicit transaction end with COMMIT,
ROLLBACK
BTET Semantics • Each statement commits automatically No Yes (Default)
Or
• Explicit transaction start using “BT”
• Explicit end using “ET” / “Rollback”
Checkpoints • Allows user to define intermediate steps within Yes No
a transaction
• Can explicitly commit or rollback to a named
checkpoint within transaction
Autonomous • Allows transactions to be defined in an Yes Yes*
Transaction independent context (*using Global
• Transaction can commit / rollback Temporary Trace
independent of main transaction Tables)

19 © 2014 Teradata
Stored Procedure Conversion – Other considerations

• Stored procedure conversion should also consider


– Conversion of “row based” (cursor) code to “set based” code
– Conversion of recursive stored procedures
– File Handling

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

Oracle Logic Teradata Logic


Open Cursor
Loop until not found insert into table
insert into table Select <columns>
values from current cursor From <cursor SQL>;
record
End loop
Close Cursor
21 © 2014 Teradata
Stored Procedure Conversion: Recursive Procedures

• Recursive stored procedures


– Recursive stored procedures are typically “row based”
– Teradata has a stored procedure nesting limit of 15.
– This might cause procedure working in Oracle to fail if converted “as is” to
Teradata
– Where possible recursive procedure should be converted to
- non-recursive procedures that are “set based” and may involve recursive SQL
- Non-recursive procedures that are “row based” but use nested loops instead of
recursion

22 © 2014 Teradata
Stored Procedure Conversion: File Handling

• Oracle has built-in package UTL_FILE to manage file IO.


• Teradata does not have out of the box equivalent procedure
• Where possible file handling should be done via TPT scripts that first load
data from file or write to file. This is a preferred option for very large data
sets.
• Another approach is to create external stored procedures that perform
file handling and invoke these stored procedures where necessary

23 © 2014 Teradata
Package Conversion

1 Oracle
Package
=
• Teradata does not have the concept of packages.
1 Teradata
Database

• Package conversion options


– Recommended Option :
- 1 Package = 1 Database
- 1 Package procedure = 1 Teradata stored procedure
- Retains <Package>.<Procedure> convention for referencing package objects
- Requires multiple databases (same as number of packages)

– Option 2: 1 Package + Procedure = 1 Teradata stored procedure


- Does not retain <Package>.<Procedure> syntax. Each reference to package procedure needs to
be changed
- Reduces number of databases
- Procedure names will need to be changed to reflect package name where procedure was
defined in Oracle or if same procedure name occurs in multiple packages.
24 © 2014 Teradata
Package Conversion
Oracle Package Component Teradata Equivalent
Package Specification • Package = Database

• Global Variables • Teradata “global temporary tables”


• Constants • Get / Set Stored Procedures
• Global Exceptions • Re-declare in each procedure
• Global Cursors
Package Body

• Procedures Stored Procedures

• Functions UDF/Stored Procedure


(See UDF slides)

• Package Initialization Section • Convert to a separate stored procedure


• Each converted procedure should include a
call to this procedure

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

• Similarities between SQL*Plus and BTEQ


– Running batch SQL on Teradata
– Running interactive SQL on Teradata
– “SET” commands to control transaction semantics, formatting, output and feedback levels
– Output formatting / basic reports
– Error reporting to calling routines/scripts
• Differences between SQL*Plus and BTEQ
– BTEQ does not support command line parameters
– BTEQ does not have script bind variables and substitution variables
– Silent mode
– Pre-processing scripts using Shell / PERL scripting may be required to support this
27 © 2014 Teradata
SQL*Plus Scripts with Anonymous PL/SQL Blocks

SQL Script with


Anonymous
PL/SQL
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

• Differences between SQL*Loader and TPT


– SQL*Loader can dynamically convert EBCDIC columns to ASCII during load
– SQL*Loader can generate sequence numbers for records during load
– SQL*Loader can support variable length records (TRAILING NULLCOLS)
– TPT supports multiple operators (e.g. LOAD, UPDATE, STREAM)
– TPT support calling pre-processing modules (INMODS)
– For features not supported by TPT pre-processing scripts / INMODS can be developed
29 © 2014 Teradata
Other Database Objects

30 © 2014 Teradata
External Tables

1. Small sized files


External Table
Option 1 Table 2. Only “SELECT” access
Function

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

1. For small volumes, TPT can read directly from source


2. For large volumes two step process to first unload
data from source to file and then load to Teradata
Option 2 3. Extraction & loading need to be scheduled as
Oracle DB Link TPT additional ELT jobs
4. Does not allow “on the fly” access to source table

1. Introduced with Teradata 15


2. Can be used to query data from multiple sources
including Oracle
Option 3 3. Provides syntax similar to Oracle DB link syntax
Oracle DB Link QueryGrid 4. Recommended approach for newer
implementations

32
Synonyms

• Synonyms are not supported in Teradata. For migration of synonyms, rewrite


references to synonyms with references to table/view.
• Oracle supports two types of synonyms viz. PUBLIC and PRIVATE. Approaches
listed below can be used to achieve similar functionality in Teradata

Oracle Teradata Equivalent

Private Synonym View

Public Synonym View in user’s default database

33 © 2014 Teradata
Materialized Views – Option 1

Materialized
View Join Index

• Materialized views (MV) can be replaced with join indexes (JI) in


Teradata where following criteria are met
– Based on one table / pre-joined multiple tables
– Aggregated data
– Optimizer selects use of MV vs. base table(s)
– Data in MV is updated as soon as data in base table(s) changes

34 © 2016 Teradata
Materialized Views – Option 2

Materialized Permanent
View Table + ETL

• Materialized views (MV) should be replaced with permanent tables


supported by ETL to refresh data where following criteria are met
– MV data is refreshed at fixed intervals.
– ETL schedule controls MV refresh
– MV contains features not supported in Join Indexes
– Code / 3rd party tools have explicit references to MV object

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

• Case sensitivity for character columns


– Oracle: Case Sensitive (default)
– Teradata: Case Insensitive (default)

• Set vs. Multi-set tables


– Oracle: Default Multi-set tables (allows full row duplicates)
– Teradata: Can choose set / multi-set feature when creating tables
• Null Handling
– Oracle: Null treated similar to empty string (e.g.: ‘Oracle’ ||Null returns ‘Oracle’ )
– Teradata: Null treated different to empty string. (e.g.: ‘Teradata’ ||Null returns NULL )
• Rounding
– Oracle: Default arithmetic rounding
– Teradata: Default banker’s rounding

38 © 2014 Teradata
Summary
Successful Migrations are determined by:

– Proper Level of Effort Estimations


- Approach
- Data Model Assessments
- ETL Code Assessment
- Function Conversion Assessment
- Technology Upgrades (3GL to modern tools)
– Sound Methodology
- Proven
- Practical
– Knowledgeable Resources
- Skilled staff
- Sufficient time to participate in migration

39
40
40

You might also like