Stored Procedure Transformation in Informatica

  • Upload
    jazz440

  • View
    235

  • Download
    0

Embed Size (px)

Citation preview

  • 8/10/2019 Stored Procedure Transformation in Informatica

    1/13

    Stored Procedure

    Transformation

    Stored Procedure Transformation in Informatica

    Author: Chandrashekar.S.NE-mail: [email protected]

    1

  • 8/10/2019 Stored Procedure Transformation in Informatica

    2/13

    Stored Procedure

    Transformation

    Contents:

    1. Overview...............................................................................................31.1.Stored Procedure Transformation connection mode......................................................................31.2.Using a Stored Procedure in a Mapping........................................................................................3

    2. Writing a Stored Procedure................................................................42.1. Sample Stored Procedure.............................................................................................................42.2. Supported databases....................................................................................................................4

    3. Creating a Stored Procedure Transformation...................................43.1. Changing the Stored Procedure................................................................................................... 5

    4. Configuring a Stored Procedure Transformation.............................54.1. Configuring a Connected Transformation..................................................................................... 5

    4.2. Configuring a UnConnected Transformation................................................................................!5. Creating a sampe mapping w!ic! uses stored procedureTransformation "connected#...................................................................$%. Summar&............................................................................................1'$. (ppendi).............................................................................................1'

    ".1 Comparison of Connected and Unconnected Stored Procedure Transformations.......................1#".2 Stored Procedure Transformation $mplementation Tips...............................................................11

    *.+eferences,.........................................................................................11

    2

  • 8/10/2019 Stored Procedure Transformation in Informatica

    3/13

    Stored Procedure

    Transformation

    1. Overview

    Stored Procedure transformation (passive type) is used for populating and maintaining databases.

    A stored procedure is a set of Structured Query Language (SQL) statements with an assigned namethat's stored in the database in compiled form so that it can be shared by a number of programs. heuse of stored procedures can be helpful in controlling access to data (end!users may enter or changedata but do not write procedures)" preserving data integrity (information is entered in a consistentmanner)" and improving productivity (statements in a stored procedure only need to be written onetime). #ou can run a stored procedure with the $%$&$ SQL statement in a database client tool" ustas you can run SQL statements. nlie standard SQL" however" stored procedures allow user!definedvariables" conditional statements" and other powerful programming features.

    *ote+ he stored procedure must e,ist in the source" target" or any database with a validconnection to the -ntegration Service before creating a Stored Procedure transformation

    .. Stored Procedure rans!ormation connection mode

    Stored procedures run in either connected or unconnected mode. he mode you use depends on whatthe stored procedure does and how you plan to use it in a session

    Connected.he flow of data through a mapping in connected mode also passes through theStored Procedure transformation. All data entering the transformation through the input portsaffects the stored procedure.

    "nconnected.he unconnected Stored Procedure transformation is not connected directly tothe flow of the mapping. -t either runs before or after the session" or is called by an e,pressionin another transformation in the mapping.

    *ote+Stored procedure should contain at least one input and one output parameter

    "sin# a Stored Procedure in a $appin#

    Steps to be followed+

    &reate the stored procedure in the database and test it.

    -mport or create the Stored Procedure transformation.

    /etermine whether to use the transformation as connected or unconnected.

    -f connected" map the appropriate input and output ports.

    -f unconnected" either configure the stored procedure to run pre! or post!session" or configure itto run from an e,pression in another transformation.

    Since stored procedures can run before or after the session" you may need to specify when theunconnected transformation should run. 0n the other hand" if the stored procedure is called

    3

  • 8/10/2019 Stored Procedure Transformation in Informatica

    4/13

    Stored Procedure

    Transformation

    from another transformation" you write the e,pression in another transformation that calls thestored procedure.

    &onfigure the session.

    %. &ritin# a Stored Procedure#ou write SQL statements to create a stored procedure in the database. #ou can also add otherransact!SQL statements and database!specific functions to a stored procedure.

    2.1. Sample Stored Procedure

    1elow procedure illustrates a stored procedure in 2icrosoft SQL Server 3445

    &reate procedure sp6test (7cd6val6id int"7cd6tbl6id int output"7cd6tbl6desc varchar(83)output)

    as

    select 7cd6tbl6id9cd6tbl6id"7cd6tbl6desc9e,pl6t,t from cd6val wherecd6val6id97cd6val6id

    return 4

    Stored procedure taes cd6val6id as input and returns cd6tbl6id and cd6tbl6desc as the outputvalues.-nput parameter cd6val6id is passed from informatica and return values is captured in outputparameters cd6tbl6id and cd6tbl6desc.

    2.2. Supported data'ases

    he stored procedure transformation is supported by 0racle" and other databases" such as -nformi,"2icrosoft SQL Server" and Sybase.

    Parameter ypes+

    here are three possible parameter types in stored procedures+

    (N./efines the parameter something that must be passed to the stored procedure.

    O"./efines the parameter as a returned value from the stored procedure.

    (NO"./efines the parameter as both input and output. 0nly 0racle supports this parametertype.

    4

  • 8/10/2019 Stored Procedure Transformation in Informatica

    5/13

    Stored Procedure

    Transformation

    ). Creatin# a Stored Procedure rans!ormation

    After you configure and test a stored procedure in the database" you must create the Stored Procedure

    transformation in the 2apping /esigner. here are two ways to configure the Stored Proceduretransformation+

    se the -mport Stored Procedure dialog bo, to configure the ports used by the storedprocedure.

    &onfigure the transformation manually" creating the appropriate ports for any input or outputparameters.

    Stored Procedure transformations are created as *ormal type by default" which means that they runduring the mapping" not before or after the session.

    3.1. Chan#in# the Stored Procedure

    -f the number of parameters or the return value in a stored procedure changes" you can either re!importit or edit the Stored Procedure transformation manually. he /esigner does not verify the StoredProcedure transformation each time you open the mapping. After you import or create thetransformation" the /esigner does not validate the stored procedure. he session fails if the storedprocedure does not match the transformation.

    *ote+ :or more information on creating a stored procedure transformation please go throughinformatica help.

    5

  • 8/10/2019 Stored Procedure Transformation in Informatica

    6/13

    Stored Procedure

    Transformation

    *. Con!i#urin# a Stored Procedure rans!ormation

    4.1. Con!i#urin# a Connected rans!ormation

    1elow figure shows a mapping that sends the cd6val6id from the Source Qualifier to an input parameterin the Stored Procedure transformation and retrieves an output parameters (cd6tbl6id"cd6tbl6desc) fromthe Stored Procedure transformation that is sent to the target. $very row of data in the Source Qualifiertransformation passes data through the Stored Procedure transformation+

    ;e

  • 8/10/2019 Stored Procedure Transformation in Informatica

    7/13

    Stored Procedure

    Transformation

    =owever" ust lie a connected mapping" you can apply the stored procedure to the flow of data throughthe mapping. -n fact" you have greater fle,ibility since you use an e,pression to call the storedprocedure" which means you can select the data that you pass to the stored procedure as an inputparameter.

    *ote+ :or more information on configuring stored procedure transformation please go throughinformatica help.

    7

  • 8/10/2019 Stored Procedure Transformation in Informatica

    8/13

    Stored Procedure

    Transformation

    . Creatin# a sample mappin# which uses stored procedurerans!ormation connected/

    &reate the stored procedure in the database+

    1elow procedure was written in the database (2icrosoft SQL Server 3445)

    create procedure sp6test (7cd6val6id int"7cd6tbl6id int output"7cd6tbl6desc varchar(83) output)

    as

    select 7cd6tbl6id9cd6tbl6id"7cd6tbl6desc9e,pl6t,t from cd6val where cd6val6id97cd6val6id

    return 4

    stored procedure taes cd6val6id as input and returns cd6tbl6id and cd6tbl6desc as the output values.

    -nput parameter cd6val6id is passed from informatica and return values is captured in outputparameters cd6tbl6id and cd6tbl6desc.

    &reate a mapping in designer.

    -mport the stored procedure

    8

  • 8/10/2019 Stored Procedure Transformation in Informatica

    9/13

    Stored Procedure

    Transformation

    Sample mapping will loo as below.

    &onfiguring the stored procedure transformation

    9

  • 8/10/2019 Stored Procedure Transformation in Informatica

    10/13

    Stored Procedure

    Transformation

    Above window shows the properties that can be set for a stored procedure transformation.Stored procedure name+ -t is the name used by integration service to call stored procedure.&onnection information+ =ere you can give the connection string to connect to database. 1y default

    it is set to >target variable .#ou can overwrite this in worflow manager.&all te,t+ e,t used by integration service to called stored procedure when it is not of normal type.$,ecution order+ 0rder in which the stored procedure need to be called in case of multiple storedprocedures. sed in case stored procedure is a not of normal type.racing level+ -t is used for debugging purpose.

    Setting Stored procedure properties in worflow manager.

    10

  • 8/10/2019 Stored Procedure Transformation in Informatica

    11/13

    Stored Procedure

    Transformation

    11

  • 8/10/2019 Stored Procedure Transformation in Informatica

    12/13

    Stored Procedure

    Transformation

    0. Summar-n Summary" we can say that stored procedure transformation can be used for populating andmanaging the database. -t can be used similar to looup transformation. Stored Procedureransformation can be used in connected or unconnected mode. -t can be used to do calculations

    which could otherwise mae mapping comple,.

    2. Appendi,

    7.1 Comparison of Connected and Unconnected Stored Procedure Transformations

    nconnected stored procedure transformation is used when+ Stored procedure need to be called before or after a session

    Stored procedure need to be run once either as pre! or post!session Stored procedure need to be run based on the row passing through stored procedure

    Stored procedure need to be called multiple times in a mapping

    &onnected stored procedure transformation is used when+ Stored procedure need to be run for every row passing through the stored procedure

    transformation Stored procedure returns a single or multiple output parameters by accepting a input

    parameters

    *ote+ unconnected stored procedure transformation can be used where ever connected storedprocedure transformation is used but not vise versa.

    7.2 Stored Procedure Transformation Implementation Tips

    0ne cannot use a stored procedure without an input and an output port. #ou need to have atleast one input and one output parameter. -f there is a stored procedure without an input andoutput parameter then u can use it with by creating one dummy input and one dummy outputparameter.

    ;esults sets from an output of a stored procedure cannot be handled in informatica. -t can behandled by using the

  • 8/10/2019 Stored Procedure Transformation in Informatica

    13/13

    Stored Procedure

    Transformation

    !!!!!!!!!!!!!!!!!!!!!!!!!!!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@!!!!!!!!!!!!!!!!!!!!!!!!

    13