You are on page 1of 7

STORED PROCEDURE T/F

Passive Transformation Connected and Unconnected Transformation Stored procedures are stored and run within the database. 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 S ! statements. Use of Stored Procedure in mapping: Check the status of a target database before loading data into it. Determine if enough space e"ists in a database. Perform a speciali#ed calculation. Drop and recreate inde"es. Mostl$ used for this in pro%ects. Data Passes &etween 'S and Stored Procedure (ne of the most useful features of stored procedures is the abilit$ to send data to the stored procedure) and receive data from the stored procedure. There are three t$pes of data that pass between the 'ntegration Service and the stored procedure* Input/output parameters: Parameters we give as input and the parameters returned from Stored Procedure. Return values: +alue returned b$ Stored Procedure if an$. Status codes: Status codes provide error handling for the 'S during a workflow. The stored procedure issues a status code that notifies whether or not the stored procedure completed successfull$. ,e cannot see this value. The 'S uses it to determine whether to continue running the session or stop. Specif$ing when the Stored Procedure -uns Normal: The stored procedure runs where the transformation e"ists in the mapping on a row.b$.row basis. ,e pass some input to procedure and it returns some calculated values. Connected stored procedures run onl$ in normal mode. Pre-load of the Source: &efore the session retrieves data from the source) the stored procedure runs. This is useful for verif$ing the e"istence of tables or performing %oins of data in a temporar$ table. Post-load of the Source: After the session retrieves data from the source) the stored procedure runs. This is useful for removing temporar$ tables. Pre-load of the Target: &efore the session sends data to the target) the stored procedure runs. This is useful for dropping inde"es or disabling constraints. Post-load of the Target: After the session sends data to the target) the stored procedure runs. This is useful for re.creating inde"es on the database. Using a Stored Procedure in a Mapping :

/. Create the stored procedure in the database. 0. 'mport or create the Stored Procedure transformation. 1. Determine whether to use the transformation as connected or unconnected. 2. 'f connected) map the appropriate input and output ports. 3. 'f unconnected) either configure the stored procedure to run pre. or post.session) or configure it to run from an e"pression in another transformation. 4. Configure the session. Stored Procedures: Connect to Source data ase and create the stored procedures given elo!: C-5AT5 (- -5P!AC5 procedure sp6agg 7in6deptno in number) ma"6sal out number) min6sal out number) avg6sal out number) sum6sal out number8 As &egin select ma"7Sal8)min7sal8)avg7sal8)sum7sal8 into ma"6sal)min6sal)avg6sal)sum6sal from emp where deptno9in6deptno group b$ deptno: 5nd: ; C-5AT5 (- -5P!AC5 procedure sp6unconn6/6value7in6deptno in number) ma"6sal out number8 As &egin Select ma"7Sal8 into ma"6sal from 5MP where deptno9in6deptno: 5nd: ; "# Connected Stored Procedure T/$ %&ample: To give input as D5PT<( from D5PT table and find the MA=) M'<) A+> and SUM of SA! from 5MP table. D5PT will be source table. Create a target table SP6C(<<65=AMP!5 with fields D5PT<() MA=6SA!) M'<6SA!) A+>6SA! ? SUM6SA!. ,rite Stored Procedure in Database first and Create shortcuts as needed. Creating Mapping: /. (pen folder where we want to create the mapping. 0. Click Tools .@ Mapping Designer. 1. Click Mapping.@ Create.@ >ive name. 5"* m6SP6C(<<65=AMP!5 2. Drag D5PT and Target table.

3. Transformation .@ 'mport Stored Procedure .@ >ive Database Connection .@ Connect .@ Select the procedure sp6agg from the list. 4. Drag D5PT<( from S 6D5PT to the stored procedure input port and also to D5PT<( port of target. A. Connect the ports from procedure to target as shown below* B. Mapping .@ +alidate C. -epositor$ .@ Save Create Session and then workflow. >ive connection information for all tables. >ive connection information for Stored Procedure also. -un workflow and see the result in table.

'# Unconnected Stored Procedure T/$ : An unconnected Stored Procedure transformation is not directl$ connected to the flow of data through the mapping. 'nstead) the stored procedure runs either* Drom an e"pression* Called from an e"pression transformation. Pre. or post.session* -uns before or after a session.

Method of returning the value of output parameters to a port* Assign the output value to a local variable. Assign the output value to the s$stem variable P-(C6-5SU!T. 7See !ater8 %&ample ": D5PT<( as input and get MA= of Sal as output. D5PT will be source table. Create a target table with fields D5PT<( and MA=6SA! of decimal data t$pe. ,rite Stored Procedure in Database first and Create shortcuts as needed. Creating Mapping: /. (pen folder where we want to create the mapping. 0. Click Tools .@ Mapping Designer. 1. Click Mapping.@ Create.@ >ive name. 5"* m6sp6unconn6/6value 2. Drag D5PT and Target table. 3. Transformation .@ 'mport Stored Procedure .@ >ive Database Connection .@ Connect .@ Select the procedure sp6unconn6/6value from the list. Click (E. 4. Stored Procedure has been imported. A. T;D .@ Create 5"pression T;D. Pass D5PT<( from S 6D5PT to 5"pression T;D. B. 5dit e"pression and create an output port (UT6MA=6SA! of decimal data t$pe. C. (pen 5"pression editor and call the stored procedure as below*Click (E and connect the port from e"pression to target as in mapping below*

/F. Mapping .@ +alidate //. -epositor$ Save. Create Session and then workflow. >ive connection information for all tables. >ive connection information for Stored Procedure also. -un workflow and see the result in table. PR(C)R%SU*T use: 'f the stored procedure returns a single output parameter or a return value) we the reserved variable P-(C6-5SU!T as the output variable. %&ample: D5PT<( as 'nput and MA= Sal as output * *SP.SP6U<C(<<6/6+A!U57D5PT<()P-(C6-5SU!T8

'f the stored procedure returns multiple output parameters) $ou must create variables for each output parameter. %&ample: D5PT<( as 'nput and MA=6SA!) M'<6SA!) A+>6SA! and SUM6SA! as output then* /. Create four variable ports in e"pression +A-6MA=6SA!)+A-6M'<6SA!) +A-6A+>6SA! and i+A-6SUM6SA!. 0. Create four output ports in e"pression (UT6MA=6SA!) (UT6M'<6SA!) (UT6A+>6SA! and (UT6SUM6SA!. 1. Call the procedure in last variable port sa$s +A-6SUM6SA!. *SP.SP6A>> 7D5PT<() +A-6MA=6SA!)+A-6M'<6SA!) +A-6A+>6SA!) P-(C6-5SU!T8 %&ample ': D5PT<( as 'nput and MA=6SA!) M'<6SA!) A+>6SA! and SUM6SA! as (;P Stored Procedure to drop inde" in Pre !oad of Target Stored Procedure to create inde" in Post !oad of Target D5PT will be source table. Create a target table SP6U<C(<<65=AMP!5 with fields D5PT<() MA=6SA!) M'<6SA!) A+>6SA! ? SUM6SA!. ,rite Stored Procedure in Database first and Create shortcuts as needed. Stored procedures are given below to drop and create inde" on target.Make sure to create target table first. Stored Procedures to be created in ne"t e"ample in Target Database*

Create or replace procedure C-5AT56'<D5= As &egin 5"ecute immediate Gcreate inde" SP6U<C(<<65=AMP!57D5PT<(8G: 5nd: ; Create or replace procedure D-(P6'<D5= As

unconn6dept

on

&egin 5"ecute immediate Gdrop inde" unconn6deptG: 5nd: ; Creating Mapping: /. (pen folder where we want to create the mapping. 0. Click Tools .@ Mapping Designer. 1. Click Mapping.@ Create.@ >ive name. 5"* m6sp6unconn6/6value 2. Drag D5PT and Target table. 3. Transformation .@ 'mport Stored Procedure .@ >ive Database Connection .@ Connect .@ Select the procedure sp6agg from the list. Click (E. 4. Stored Procedure has been imported. A. T;D .@ Create 5"pression T;D. Pass D5PT<( from S 6D5PT to 5"pression T;D. B. 5dit 5"pression and create 2 variable ports and 2 output ports as shown below*

C. Call the procedure in last variable port +A-6SUM6SA!. /F. *SP.SP6A>> 7D5PT<() +A-6MA=6SA!) +A-6M'<6SA!) +A-6A+>6SA!) P-(C6-5SU!T8 //. Click Appl$ and (k. /0. Connect to target table as needed. /1. Transformation .@ 'mport Stored Procedure .@ >ive Database Connection for target .@ Connect .@ Select the procedure C-5AT56'<D5= and D-(P6'<D5= from the list. Click (E. /2. 5dit D-(P6'<D5= .@ Properties Tab .@ Select Target Pre !oad as Stored Procedure T$pe and in call te"t write drop6inde". Click Appl$ .@ (k. /3. 5dit C-5AT56'<D5= .@ Properties Tab .@ Select Target Post !oad as Stored Procedure T$pe and in call te"t write create6inde". Click Appl$ .@ (k. /4. Mapping .@ +alidate /A. -epositor$ .@ Save

Create Session and then workflow. >ive connection information for all tables. >ive connection information for Stored Procedures also. Also make sure that $ou e"ecute the procedure C-5AT56'<D5= on database before using them in mapping. This is because) if there is no '<D5= on target table) D-(P6'<D5= will fail and Session will also fail. -un workflow and see the result in table.