A Stored Procedure is an important tool for populating and maintaining databases. Since stored procedures allow greater flexibility than SQL statements, database developers and programmers use stored procedures for various tasks within databases. Informatica PowerCenter provides Stored Procedure Transformation to leverage the power of Database Scripting. In this article lets see it in more in detail about how to use Stored Procedure Transformation.
For the demonstration purpose lets consider a scenario.
Customer source data arrives in a flat file from each store. At times, the customer names may contain some invalid data. All customer names should be validated to check for spaces, digits, special characters, etc. so that there is valid customer data in the Data Mart.
- Use a Stored Procedure transformation to validate the customer name.
- Connected Stored Procedure Transformation OR
- Un-Connected Stored Procedure Transformation
Below is the layout of the completed mapping.
I. Copy the mapping
We will be using the mapping created in the prior demo article. Copy the mapping to continue this exercise.
- In the Navigator Window, select the mapping M_Custid_x.
- Select the menu option EDIT | COPY and then select EDIT | PASTE.
- Rename the mapping as M_CheckCustName_x.
II. Use a Connected Stored Procedure Transformation
- To create a Stored Procedure transformation
- Select TRANSFORMATION | CREATE and select Stored Procedure from the drop down, or
- Click on the icon from the Transformation toolbar.
- Enter the name of the transformation as SP_CheckCustName_x.
- Select the procedure name from the PROCEDURES folder.
- The Stored Procedure transformation appears with two ports: Name and Flag as shown below.
- Double click on the stored procedure transformation. Note : The procedure contains two parameters, Name which is an IN parameter and FLAG, which is an OUT parameter.
- Delete the existing links between the Source Qualifier and Tgt_Customer_x.
- Link Firstname port from Source Qualifier into the Name port of the Stored Procedure transformation.
- Create a Filter transformation and link all ports from Source Qualifier into Filter transformation.
- Link the FLAG port from Stored Procedure into the Filter.
- Create the filter condition : FLAG = ‘V’.
- Link all ports except FLAG into the target.
- The Sequence Generator transformation will generate the Customer_id in the target. Only rows with valid customer names will pass to the target.
- The final mapping should look as given below:
III. Load the Target
IV. Verify the ResultsSelect the data from the target table. All the names are clean with no special characters or numbers.
V. Using an Unconnected Stored Procedure Transformation
- Using the same mapping, remove the existing Stored Procedure transformation.
- Create the Stored Procedure transformation again. Do not link it to any other transformation. Note : An Unconnected Stored Procedure transformation does not contain any links to other transformations.
- The ports in the Unconnected Stored Procedure will appear as follows :
- In the same mapping, create an Expression transformation before the Filter transformation. Link relevant Ports.
- To call the Stored Procedure from the Expression transformation, enter the expression for the FLAG column, the newly added output port as shown below:
- FirstName is passed as a parameter to the Stored Procedure and the value returned by the Stored Procedure will be available in the PROC_RESULT variable.
- Link all ports from Expression transformation into the filter. Complete the rest of the mapping as shown below:
IV. Load the Target
- Create a Workflow with the name wf_CheckCustName_Unconnected_x.
- Create a session task with the name s_CheckCustName_Unconnected_x
- Run the Workflow.
- Monitor the Workflow.
Hope you enjoyed this tutorial, Please let us know if you have any difficulties in trying out these exercise and subscribe to the mailing list to get the latest tutorials in your mail box.