Thursday, May 26, 2011

Stored Procedure Transformation


Stored Procedure Transformation
Transformation type:
 Passive
Connected/Unconnected

A Stored Procedure transformation is an important tool for populating and maintaining databases. Database administrators create stored procedures to automate tasks that are too complicated for standard SQL statements.
A stored procedure is a precompiled collection of Transact-SQL, PL-SQL or other database procedural statements and optional flow control statements, similar to an executable script. Stored procedures are stored and run within the database.
You can run a stored procedure with the EXECUTE SQL statement in a database client tool, just as you can run SQL statements. Unlike standard SQL, however, stored procedures allow user-defined variables, conditional statements, and other powerful programming features
You might use stored procedures to complete the following tasks:
ü  *
Check the status of a target database before loading data into it.
ü  *
Determine if enough space exists in a database.

ü  *
Perform a specialized calculation.
ü  *
Drop and recreate indexes.

The stored procedure must exist in the database before creating a Stored Procedure transformation, and the stored procedure can exist in a source, target, or any database with a valid connection to the Integration Service
You might use a stored procedure to perform a query or calculation that you would otherwise make part of a mapping. For example, if you already have a well-tested stored procedure for calculating sales tax, you can perform that calculation through the stored procedure instead of recreating the same calculation in an Expression transformation.
One of the most useful features of stored procedures is the ability to send data to the stored procedure, and receive data from the stored procedure.
Input/Output Parameters
For many stored procedures, you provide a value and receive a value in return. These values are known as input and output parameters.
For example, a sales tax calculation stored procedure can take a single input parameter, such as the price of an item. After performing the calculation, the stored procedure returns two output parameters, the amount of tax, and the total cost of the item including the tax.
The Stored Procedure transformation sends and receives input and output parameters using ports, variables, or by entering a value in an expression, such as 10 or SALES.
If a stored procedure returns a result set rather than a single return value, the Stored Procedure transformation takes only the first value returned from the procedure
Connected and Unconnected
*
Connected. The flow of data through a mapping in connected mode also passes through the Stored Procedure transformation. All data entering the transformation through the input ports affects the stored procedure. You should use a connected Stored Procedure transformation when you need data from an input port sent as an input parameter to the stored procedure, or the results of a stored procedure sent as an output parameter to another transformation.
*
Unconnected. The unconnected Stored Procedure transformation is not connected directly to the flow of the mapping. It either runs before or after the session, or is called by an expression in another transformation in the mapping.
The following table compares connected and unconnected transformations:
If you want to
Use this mode
Run a stored procedure before or after a session.
Unconnected
Run a stored procedure once during a mapping, such as pre- or post-session.
Unconnected
Run a stored procedure every time a row passes through the Stored Procedure transformation.
Connected or Unconnected
Run a stored procedure based on data that passes through the mapping, such as when a specific port does not contain a null value.
Unconnected
Pass parameters to the stored procedure and receive a single output parameter.
Connected or Unconnected
Pass parameters to the stored procedure and receive multiple output parameters.
Note: To get multiple output parameters from an unconnected Stored Procedure transformation, you must create variables for each output parameter.
Connected or Unconnected
Run nested stored procedures.
Unconnected
Call multiple times within a mapping.
Unconnected
Connected stored procedures run only in normal mode.
*
Normal. The stored procedure runs where the transformation exists in the mapping on a row-by-row basis. This is useful for calling the stored procedure for each row of data that passes through the mapping, such as running a calculation against an input port. Connected stored procedures run only in normal mode.
*
Pre-load of the Source. Before the session retrieves data from the source, the stored procedure runs. This is useful for verifying the existence of tables or performing joins of data in a temporary table.

*
Post-load of the Source. After the session retrieves data from the source, the stored procedure runs. This is useful for removing temporary tables.
*
Pre-load of the Target. Before the session sends data to the target, the stored procedure runs. This is useful for verifying target tables or disk space on the target system.

*
Post-load of the Target. After the session sends data to the target, the stored procedure runs. This is useful for re-creating indexes on the database.
To run multiple stored procedures that use the same database connection, set these stored procedures to run consecutively. If you do not set them to run consecutively, you might have unexpected results in the target. For example, you have two stored procedures: Stored Procedure A and Stored Procedure B. Stored Procedure A begins a transaction, and Stored Procedure B commits the transaction. If you run Stored Procedure C before Stored Procedure B, using another database connection, Stored Procedure B cannot commit the transaction because the Integration Service closes the database connection when it runs Stored Procedure C.
Note: The Integration Service fails sessions that contain stored procedure arguments with large objects.
Notice that the return value is a string value (Success) with the datatype VARCHAR2. Oracle is the only database to allow return values with string datatypes.
There are three ways to import a stored procedure in the Mapping Designer:
*
Select the stored procedure icon and add a Stored Procedure transformation.
*
Click Transformation > Import Stored Procedure.

*
Click Transformation > Create, and then select Stored Procedure.

When you import a stored procedure containing a period (.) in the stored procedure name, the Designer substitutes an underscore (_) for the period in the Stored Procedure transformation name.




No comments:

Post a Comment