0% found this document useful (0 votes)
47 views41 pages

Migration From Oracle To TD

Uploaded by

imusmanahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views41 pages

Migration From Oracle To TD

Uploaded by

imusmanahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

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 © 2014
2
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
Business Business Single View of the
Business

Business Questions Business Questions Business Questions


(Complexity) (Complexity) (Complexity)

Cost of Ownership Cost of Ownership Cost of Ownership


© 2014

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
Functions Supported “AS IS”

Numeric Character Date / Time Aggregate / Other


Functions Functions Functions Analytic Functions
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_SX
X,
REGR_SXY
,
REGR_SYY

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

Expressions that can be coded


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

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

• 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.

1 © 2014
Stored Procedures

12 © 2014 Teradata
Stored Procedure

Oracle Stored Teradata Stored Procedure


Procedure

• Stored procedure conversion primarily involves converting


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

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

- 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

1 © 2014
Stored Procedure Conversion : Variable

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

1 © 2014
Stored Procedure Conversion : Exception

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 ; CONDITION FOR SQLSTATE VALUE
Database defined error pragma exception_init ‘52004’;
number (user_role_not_exists, -1917) ;

1 © 2014
Stored Procedure Conversion : Exception

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

1 © 2014
Stored Procedure Conversion : Transaction

Transaction Features Oracle Teradata


Handling Supported? Supported?
Feature
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 Yes Yes*
Transaction an independent context (*using Global
• Transaction can commit / rollback Temporary
independent of main transaction Trace Tables)

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

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

2 © 2014
Stored Procedure Conversion: Recursive

• 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

2 © 2014
Stored Procedure Conversion: File

• 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

2 © 2014
Package

=
1 Oracle Package 1 Teradata Database

• Teradata does not have the concept of packages.


• 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.

2 © 2014
Package
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

2 © 2014
Oracle Scripts

26 © 2014 Teradata
SQL*Plus Script

Shell / PERL BTEQ Script


SQL*Plus Script
Scripts + + 1 Stored Proc. per A

• 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

2 © 2014
SQL*Plus Scripts with Anonymous

SQL Script with Anonymous BTEQ


PL/SQL Script

+ 1 Stored Proc. per Anonymou

– 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

Pre- processing script TPT Script


SQL*Loader 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

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

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


2. For large volumes two step process to first
Oracle DB Link
Option 2
TPT unload data from source to file and then load to
Teradata
3. Extraction & loading need to be scheduled as
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
Oracle DB Link
Option 3
QueryGrid including Oracle
3. Provides syntax similar to Oracle DB link syntax
4. Recommended approach for newer
implementations

3
Synony

• 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

Oracl Teradata Equivalent


e
Private Synonym View
Public Synonym View in user’s default database

3 © 2014
Materialized Views –
Join Index
Materialized
View

• 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

3 © 2016
Materialized Views –
Permanent
Materialized
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

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

• 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

3 © 2014
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

3
40
4
0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy