Friday, April 5, 2013

Stored Procedure Transformation

Stored Procedure is an Passive and Connected/Unconnected transformation.

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.

Not all databases support stored procedures, and stored procedure syntax varies depending on the database. 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. 
Input and Output Data
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.

There are three types of data that pass between the Integration Service and the stored procedure:
  • Input/output parameters: Parameters which we pass to the SP.
  • Return values: Value return by the SP.
  • Status codes: Status codes provide error handling for the Integration Service during a workflow. The stored procedure issues a status code that notifies whether or not the stored procedure completed successfully. You cannot see this value. The Integration Service uses it to determine whether to continue running the session or stop. You configure options in the Workflow Manager to continue or stop the session in the event of a stored procedure error.
Connected and Unconnected
Stored procedures run in either connected or unconnected mode. The mode you use depends on what the stored procedure does and how you plan to use it in a session. You can configure connected and unconnected Stored Procedure transformations in a mapping.

  • 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

Specifying when the Stored Procedure Runs
In addition to specifying the mode of the Stored Procedure transformation, you also specify when it runs. In the case of the unconnected stored procedure it runs every time a row passes through it. However, you have the option to run the stored procedure once before or after the session.

The following list describes the options for running a Stored Procedure transformation:
  • 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
You can run more than one Stored Procedure transformation in different modes in the same mapping.

Note:  We can you 2 types of Store Procedure in Informatica:
1. The Store Procedure which returns the value (connected/un-connected) which is apart the data flow.
2. The Store Procedure which execute inside the database which is used to refresh the data, do some modification, copy the data from one table to other etc. Which means it will not have any return values. Which can be called anywhere Pre-Post (source/target) or Normal (within the flow).

To use a Stored Procedure transformation, complete the following steps:
  1. Create the stored procedure in the database.
  2. Import or create the Stored Procedure transformation.
  3. Determine whether to use the transformation as connected or unconnected.
  4. If connected, map the appropriate input and output ports.
  5. If unconnected, either configure the stored procedure to run pre- or post-session, or configure it to run from an expression in another transformation.
  6. Configure the session.
Sample Stored Procedure

Mapping will be uploaded soon..

9 comments:

  1. Hi Gowtham, can you share the sample of stored procedure transformation...

    ReplyDelete
  2. where is the sample?

    ReplyDelete
  3. Hi Gowtham,thanks for sharing all Transformations in informatica. Can u please share sample of Stored Procedure Transformation...

    ReplyDelete
  4. sorry.. provide one* sample for stored procedure

    ReplyDelete
  5. Hi Gowtham please share one stored prodcedure example.

    Thanks
    Anonymous

    ReplyDelete
  6. Thanks for Sharing useful Information..!

    ReplyDelete
  7. WHEN DO WE USE THE RETURN PORT CHECK BOX IN A STORED PROCEDURE TRANSFORMATION? CAN SOMEONE HELP ME WITH AN EXAMPLE

    ReplyDelete