Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
103 views

Informatica Transformations Ans SQL Queries PDF Free

A transformation is an object in Informatica that processes or modifies data. There are different types of transformations including active transformations which change the number of rows, passive transformations which do not change rows, and connected/unconnected transformations based on how they are connected in a mapping. Aggregator transformations perform aggregation functions like sum, count, average on groups of rows to calculate metrics. Expressions transformations calculate values on a row-by-row basis.

Uploaded by

Sreenath Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Informatica Transformations Ans SQL Queries PDF Free

A transformation is an object in Informatica that processes or modifies data. There are different types of transformations including active transformations which change the number of rows, passive transformations which do not change rows, and connected/unconnected transformations based on how they are connected in a mapping. Aggregator transformations perform aggregation functions like sum, count, average on groups of rows to calculate metrics. Expressions transformations calculate values on a row-by-row basis.

Uploaded by

Sreenath Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

developer.

1. What is a transformation?
10. How do you promote a non-reusable
A transformation is a repository object that
transformation to reusable transformation?
generates, modifies, or passes data.
Edit the transformation and check the Make
Reusable option
2. What is an active transformation?
An active transformation is the one which
11. How to create a non-reusable instance of
changes the number of rows that pass through
reusable transformations?
it.
In the navigator, select an existing
Example: Filter transformation
transformation and drag the transformation into
the mapping workspace. Hold down the Ctrl key
3. What is a passive transformation?
before you release the transformation.
A passive transformation is the one which does
not change the number of rows that pass
12. Which transformation can be created only as
through it.
reusable transformation but not as non-reusable
Example: Expression transformation
transformation?
External procedure transformation.
4. What is a connected transformation?
A connected transformation is connected to the INFORMATICA INTERVIEW QUESTIONS ON
data flow or connected to the other AGGREGATOR TRANSFORMATION
transformations in the mapping pipeline.
1. What is aggregator transformation?
Example: sorter transformation
Aggregator transformation performs aggregate
calculations like sum, average, count etc. It is an
5. What is an unconnected transformation?
active transformation, changes the number of
An unconnected transformation is not connected
rows in the pipeline. Unlike expression
to other transformations in the mapping. An
transformation (performs calculations on a row-
unconnected transformation is called within
by-row basis), an aggregator transformation
another transformation and returns a value to
performs calculations on group of rows.
that transformation.
Example: Unconnected lookup transformation,
2. What is aggregate cache?
unconnected stored procedure transformation
The integration service creates index and data
cache in memory to process the aggregator
6. What are multi-group transformations?
transformation and stores the data group in
Transformations having multiple input and
index cache, row data in data cache. If the
output groups are called multi-group
integration service requires more space, it stores
transformations.
the overflow values in cache files.
Examples: Custom, HTTP, Joiner, Router,
Union, Unstructured Data, XML source qualifier,
3. How can we improve performance of
XML Target definition, XML parser, XML
aggregate transformation?
generator
 Use sorted input: Sort the data before
7. List out all the transformations which use passing into aggregator. The integration service
cache? uses memory to process the aggregator
Aggregator, Joiner, Lookup, Rank, Sorter transformation and it does not use cache
memory.
8. What is blocking transformation?  Filter the unwanted data before
Transformation which blocks the input rows are aggregating.
called blocking transformation.  Limit the number of input/output or
Example: Custom transformation, unsorted output ports to reduce the amount of data the
joiner aggregator transformation stores in the data
cache.
9. What is a reusable transformation?
A reusable transformation is the one which can
4. What are the different types of aggregate
be used in multiple mappings. Reusable
functions?
transformation is created in transformation
The different types of aggregate functions are INFORMATICA INTERVIEW QUESTIONS ON
listed below: EXPRESSION TRANSFORMATION
AVG,COUNT,,FIRST,LAST,MAX,MEDIAN,MIN,
1. What is an expression transformation?
PERCENTILE,STDDEV,SUMVARIANCE
An expression transformation is used to
5. Why cannot you use both single level and calculate values in a single row.
nested aggregate functions in a single Example: salary+1000
aggregate transformation?
2. How to generate sequence numbers using
The nested aggregate function returns only one expression transformation?
output row, whereas the single level aggregate Create a variable port in expression
function returns more than one row. Since the transformation and increment it by one for every
number of rows returned are not same, you row. Assign this variable port to an output port.
cannot use both single level and nested
aggregate functions in the same transformation. 3. Consider the following employees data as
If you include both the single level and nested source?
functions in the same aggregator, the designer
marks the mapping or mapplet as invalid. So, Employee_id, Salary
you need to create separate aggregator 10, 1000
transformations. 20, 2000
30, 3000
6. Up to how many levels, you can nest the 40, 5000
aggregate functions?
Q1. Design a mapping to load the cumulative
We can nest up to two levels only. sum of salaries of employees into target table?
Example: MAX( SUM( ITEM ) ) The target table data should look like as
Employee_id, Salary, Cumulative_sum
7. What is incremental aggregation? 10, 1000, 1000
20, 2000, 3000
The integration service performs aggregate 30, 3000, 6000
calculations and then stores the data in historical 40, 5000, 11000
cache. Next time when you run the session, the
integration service reads only new data and Q2. Design a mapping to get the pervious row
uses the historical cache to perform new salary for the current row. If there is no pervious
aggregation calculations incrementally. row exists for the current row, then the pervious
row salary should be displayed as null.
8. Why cannot we use sorted input option for The output should look like as
incremental aggregation? Employee_id, Salary, Pre_row_salary
10, 1000, Null
In incremental aggregation, the aggregate
20, 2000, 1000
calculations are stored in historical cache on the
30, 3000, 2000
server. In this historical cache the data need not
40, 5000, 3000
be in sorted order. If you give sorted input, the
records come as presorted for that particular run
4. Consider the following employees table as
but in the historical cache the data may not be in
source
the sorted order. That is why this option is not
allowed. Department_no, Employee_name
9. How the NULL values are handled in 20, R
10, A
Aggregator?
10, D
20, P
You can configure the integration service to treat
10, B
null values in aggregator functions as NULL or
10, C
zero. By default the integration service treats
20, Q
null values as NULL in aggregate functions.
20, S
Q1. Design a mapping to load a target table with Q2. Design a mapping to get the pervious row
the following values from the above source? salary for the current row. If there is no pervious
row exists for the current row, then the pervious
Department_no, Employee_list row salary should be displayed as null.
10, A The output should look like as
10, A,B
10, A,B,C employee_id, salary, pre_row_salary
10, A,B,C,D 10, 1000, Null
20, A,B,C,D,P 20, 2000, 1000
20, A,B,C,D,P,Q 30, 3000, 2000
20, A,B,C,D,P,Q,R 40, 5000, 3000
20, A,B,C,D,P,Q,R,S
Solution:
Q2. Design a mapping to load a target table with
the following values from the above source? Connect the source Qualifier to expression
transformation. In the expression transformation,
Department_no, Employee_list create a variable port V_count and increment it
10, A by one for each row entering the expression
10, A,B transformation. Also create V_salary variable
10, A,B,C port and assign the expression
10, A,B,C,D IIF(V_count=1,NULL,V_prev_salary) to it . Then
20, P create one more variable port V_prev_salary
20, P,Q and assign Salary to it. Now create output port
20, P,Q,R O_prev_salary and assign V_salary to it.
20, P,Q,R,S Connect the expression transformation to the
target ports.
INFORMATICA SCENARIO BASED
In the expression transformation, the ports will
QUESTIONS - PART 2
be
1. Consider the following employees data as
source employee_id
salary
employee_id, salary V_count=V_count+1
10, 1000 V_salary=IIF(V_count=1,NULL,V_prev_salary)
20, 2000 V_prev_salary=salary
30, 3000 O_prev_salary=V_salary
40, 5000

Q1. Design a mapping to load the cumulative Q3. Design a mapping to get the next row salary
sum of salaries of employees into target table? for the current row. If there is no next row for the
The target table data should look like as current row, then the next row salary should be
displayed as null.
employee_id, salary, cumulative_sum The output should look like as
10, 1000, 1000
20, 2000, 3000 employee_id, salary, next_row_salary
30, 3000, 6000 10, 1000, 2000
40, 5000, 11000 20, 2000, 3000
30, 3000, 5000
Solution: 40, 5000, Null

Connect the source Qualifier to expression Solution:


transformation. In the expression transformation,
create a variable port V_cum_sal and in the Step1: Connect the source qualifier to two
expression editor write V_cum_sal+salary. expression transformation. In each expression
Create an output port O_cum_sal and assign transformation, create a variable port V_count
V_cum_sal to it. and in the expression editor write V_count+1.
Now create an output port O_count in each Step1: Connect the source qualifier to the
expression transformation. In the first expression expression transformation. In the expression
transformation, assign V_count to O_count. In transformation, create a dummy port and assign
the second expression transformation assign value 1 to it.
V_count-1 to O_count.
In the expression transformation, the ports will
In the first expression transformation, the ports be
will be
employee_id
employee_id salary
salary O_dummy=1
V_count=V_count+1
O_count=V_count Step2: Pass the output of expression
transformation to aggregator. Create a new port
In the second expression transformation, the O_sum_salary and in the expression editor write
ports will be SUM(salary). Do not specify group by on any
port.
employee_id
salary In the aggregator transformation, the ports will
V_count=V_count+1 be
O_count=V_count-1
salary
Step2: Connect both the expression O_dummy
transformations to joiner transformation and join O_sum_salary=SUM(salary)
them on the port O_count. Consider the first
expression transformation as Master and Step3: Pass the output of expression
second one as detail. In the joiner specify the transformation, aggregator transformation to
join type as Detail Outer Join. In the joiner joiner transformation and join on the DUMMY
transformation check the property sorted input, port. In the joiner transformation check the
then only you can connect both expression property sorted input, then only you can connect
transformations to joiner transformation. both expression and aggregator to joiner
transformation.
Step3: Pass the output of joiner transformation
to a target table. From the joiner, connect the Step4: Pass the output of joiner to the target
employee_id, salary which are obtained from the table.
first expression transformation to the
employee_id, salary ports in target table. Then 2. Consider the following employees table as
from the joiner, connect the salary which is source
obtained from the second expression
transformaiton to the next_row_salary port in the department_no, employee_name
target table. 20, R
10, A
10, D
Q4. Design a mapping to find the sum of 20, P
salaries of all employees and this sum should 10, B
repeat for all the rows. 10, C
The output should look like as 20, Q
20, S
employee_id, salary, salary_sum
10, 1000, 11000 Q1. Design a mapping to load a target table with
20, 2000, 11000 the following values from the above source?
30, 3000, 11000
40, 5000, 11000 department_no, employee_list
10, A
Solution: 10, A,B
10, A,B,C
10, A,B,C,D
20, A,B,C,D,P
20, A,B,C,D,P,Q Q3. Design a mapping to load a target table with
20, A,B,C,D,P,Q,R the following values from the above source?
20, A,B,C,D,P,Q,R,S
department_no, employee_names
Solution: 10, A,B,C,D
20, P,Q,R,S
Step1: Use a sorter transformation and sort the
data using the sort key as department_no and Solution:
then pass the output to the expression
transformation. In the expression transformation, The first step is same as the above problem.
the ports will be Pass the output of expression to an aggregator
transformation and specify the group by as
department_no department_no. Now connect the aggregator
employee_name transformation to a target table.
V_employee_list =
IIF(ISNULL(V_employee_list),employee_name,
INFORMATICA INTERVIEW QUESTIONS ON
V_employee_list||','||employee_name)
FILTER TRANSFORMATION
O_employee_list = V_employee_list
1. What is a filter transformation?
Step2: Now connect the expression
transformation to a target table. A filter transformation is used to filter out the
rows in mapping. The filter transformation allows
Q2. Design a mapping to load a target table with the rows that meet the filter condition to pass
the following values from the above source? through and drops the rows that do not meet the
condition. Filter transformation is an active
department_no, employee_list transformation.
10, A
10, A,B 2. Can we specify more than one filter condition
10, A,B,C in a filter transformation?
10, A,B,C,D
20, P We can only specify one condition in the filter
20, P,Q transformation. To specify more than one
20, P,Q,R condition, we have to use router transformation?
20, P,Q,R,S
3. In which case a filter transformation acts as
Solution: passive transformation?

Step1: Use a sorter transformation and sort the If the filter condition is set to TRUE, then it
data using the sort key as department_no and passes all the rows without filtering any data. In
then pass the output to the expression this case, the filter transformation acts as
transformation. In the expression transformation, passive transformation.
the ports will be
4. Can we concatenate ports from more than
department_no one transformation into the filter transformation?
employee_name
V_curr_deptno=department_no No. The input ports for the filter must come from
V_employee_list = IIF(V_curr_deptno! = a single transformation.
V_prev_deptno,employee_name,V_employee_li
st||','||employee_name) 5. How to filter the null values and spaces?
V_prev_deptno=department_no
O_employee_list = V_employee_list Use the ISNULL and IS_SPACES functions
Example:
Step2: Now connect the expression IIF(ISNULL(commission),FALSE,TRUE)
transformation to a target table.
6. How session performance can be improved  Full outer join: A full outer join keeps all
by using filter transformation? rows of data from both the master and detail
rows.
Keep the filter transformation as close as 5. What is joiner cache?
possible to the sources in the mapping. This
allows the unwanted data to be discarded and When the integration service processes a joiner
the integration service processes only the transformation, it reads the rows from master
required rows. If the source is relational source, source and builds the index and data cached.
use the source qualifier to filter the rows. Then the integration service reads the detail
source and performs the join. In case of sorted
INFORMATICA INTERVIEW QUESTIONS ON joiner, the integration service reads both sources
JOINER TRANSFORMATION (master and detail) concurrently and builds the
cache based on the master rows.
1. What is a joiner transformation?
6. How to improve the performance of joiner
A joiner transformation joins two heterogeneous transformation?
sources. You can also join the data from the  Join sorted data whenever possible.
same source. The joiner transformation joins
sources with at least one matching column. The  For an unsorted Joiner transformation,
joiner uses a condition that matches one or designate the source with fewer rows as the
more joins of columns between the two sources. master source.
 For a sorted Joiner transformation,
2. How many joiner transformations are required designate the source with fewer duplicate key
to join n sources? values as the master source.

To join n sources n-1 joiner transformations are 7. Why joiner is a blocking transformation?
required.
When the integration service processes an
3. What are the limitations of joiner unsorted joiner transformation, it reads all
transformation? master rows before it reads the detail rows. To
 You cannot use a joiner transformation ensure it reads all master rows before the detail
when input pipeline contains an update strategy rows, the integration service blocks all the
transformation. details source while it caches rows from the
 You cannot use a joiner if you connect a master source. As it blocks the detail source, the
sequence generator transformation directly unsorted joiner is called a blocking
before the joiner. transformation.

8. What are the settings used to configure the


4. What are the different types of joins?
joiner transformation
 Normal join: In a normal join, the
 Master and detail source
integration service discards all the rows from the
master and detail source that do not match the  Type of join
join condition.  Join condition
 Master outer join: A master outer join
keeps all the rows of data from the detail source
and the matching rows from the master source. INFORMATICA INTERVIEW QUESTIONS ON
It discards the unmatched rows from the master LOOKUP TRANSFORMATION
source. 1. What is a lookup transformation?
 Detail outer join: A detail outer join A lookup transformation is used to look up data
keeps all the rows of data from the master in a flat file, relational table, view, and synonym.
source and the matching rows from the detail
source. It discards the unmatched rows from the 2. What are the tasks of a lookup
detail source. transformation?
The lookup transformation is used to perform the
following tasks?
 Get a related value: Retrieve a value  If there is no match for the lookup
from the lookup table based on a value in the condition, connected lookup transformation
source. returns default value for all output ports. If you
 Perform a calculation: Retrieve a value configure dynamic caching, the Integration
from a lookup table and use it in a calculation. Service inserts rows into the cache or leaves it
unchanged. If there is no match for the lookup
 Update slowly changing dimension condition, the unconnected lookup
tables: Determine whether rows exist in a target. transformation returns null.
3. How do you configure a lookup  In a connected lookup transformation,
transformation? the cache includes the lookup source columns in
Configure the lookup transformation to perform the lookup condition and the lookup source
the following types of lookups: columns that are output ports. In an
 Relational or flat file lookup unconnected lookup transformation, the cache
 Pipeline lookup includes all lookup/output ports in the lookup
 Connected or unconnected lookup condition and the lookup/return port.
 Cached or uncached lookup  Connected lookup transformation
passes multiple output values to another
transformation. Unconnected lookup
4. What is a pipeline lookup transformation?
transformation passes one output value to
A pipeline lookup transformation is used to
another transformation.
perform lookup on application sources such as
JMS, MSMQ or SAP. A pipeline lookup  Connected lookup transformation
transformation has a source qualifier as the supports user-defined values. Unconnected
lookups source. lookup transformation does not support user-
defined default values.
5. What is connected and unconnected lookup
transformation? 7. How do you handle multiple matches in
 A connected lookup transformation is lookup transformation? or what is "Lookup Policy
connected the transformations in the mapping on Multiple Match"?
pipeline. It receives source data, performs a "Lookup Policy on Multiple Match" option is used
lookup and returns data to the pipeline. to determine which rows that the lookup
 An unconnected lookup transformation transformation returns when it finds multiple
is not connected to the other transformations in rows that match the lookup condition. You can
the mapping pipeline. A transformation in the select lookup to return first or last row or any
pipeline calls the unconnected lookup with a matching row or to report an error.
:LKP expression.
8. What is "Output Old Value on Update"?
This option is used when dynamic cache is
6. What are the differences between connected enabled. When this option is enabled, the
and unconnected lookup transformation? integration service outputs old values out of the
 Connected lookup transformation lookup/output ports. When the Integration
receives input values directly from the pipeline. Service updates a row in the cache, it outputs
Unconnected lookup transformation receives the value that existed in the lookup cache before
input values from the result of a :LKP expression it updated the row based on the input data.
in another transformation. When the Integration Service inserts a new row
 Connected lookup transformation can in the cache, it outputs null values. When you
be configured as dynamic or static cache. disable this property, the Integration Service
Unconnected lookup transformation can be outputs the same values out of the lookup/output
configured only as static cache. and input/output ports.
 Connected lookup transformation can
return multiple columns from the same row or 9. What is "Insert Else Update" and "Update
insert into the dynamic lookup cache. Else Insert"?
Unconnected lookup transformation can return These options are used when dynamic cache is
one column from each row. enabled.
 Insert Else Update option applies to  Concurrent caches: The Integration
rows entering the lookup transformation with the Service builds lookup caches concurrently. It
row type of insert. When this option is enabled does not need to wait for data to reach the
the integration service inserts new rows in the Lookup transformation.
cache and updates existing rows when disabled,
the Integration Service does not update existing 13. How the integration service builds the
rows. caches for unconnected lookup transformation?
 Update Else Insert option applies to The Integration Service builds caches for
rows entering the lookup transformation with the unconnected Lookup transformations as
row type of update. When this option is enabled, sequentially.
the Integration Service updates existing rows,
and inserts a new row if it is new. When 14. What is a dynamic cache?
disabled, the Integration Service does not insert The dynamic cache represents the data in the
new rows. target. The Integration Service builds the cache
when it processes the first lookup request. It
10. What are the options available to configure a queries the cache based on the lookup condition
lookup cache? for each row that passes into the transformation.
The following options can be used to configure a The Integration Service updates the lookup
lookup cache: cache as it passes rows to the target. The
 Persistent cache integration service either inserts the row in the
cache or updates the row in the cache or makes
 Recache from lookup source no change to the cache.
 Static cache
 Dynamic cache 15. When you use a dynamic cache, do you
need to associate each lookup port with the
 Shared Cache input port?
 Pre-build lookup cache Yes. You need to associate each lookup/output
port with the input/output port or a sequence ID.
11. What is a cached lookup transformation and The Integration Service uses the data in the
uncached lookup transformation? associated port to insert or update rows in the
 Cached lookup transformation: The lookup cache.
Integration Service builds a cache in memory
when it processes the first row of data in a 16. What are the different values returned by
cached Lookup transformation. The Integration NewLookupRow port?
Service stores condition values in the index The different values are
cache and output values in the data cache. The  0 - Integration Service does not update
Integration Service queries the cache for each or insert the row in the cache.
row that enters the transformation.  1 - Integration Service inserts the row
 Uncached lookup transformation: For into the cache.
each row that enters the lookup transformation,  2 - Integration Service updates the row
the Integration Service queries the lookup in the cache.
source and returns a value. The integration
service does not build a cache.
17. What is a persistent cache?
If the lookup source does not change between
12. How the integration service builds the session runs, then you can improve the
caches for connected lookup transformation? performance by creating a persistent cache for
The Integration Service builds the lookup caches the source. When a session runs for the first
for connected lookup transformation in the time, the integration service creates the cache
following ways: files and saves them to disk instead of deleting
 Sequential cache: The Integration them. The next time when the session runs, the
Service builds lookup caches sequentially. The integration service builds the memory from the
Integration Service builds the cache in memory cache file.
when it processes the first row of the data in a
cached lookup transformation.
18. What is a shared cache? the cobol sources?
You can configure multiple Lookup
transformations in a mapping to share a single Since the cobol sources contain denormalzed
lookup cache. The Integration Service builds the data, normalizer transformation is used to
cache when it processes the first Lookup normalize the cobol sources.
transformation. It uses the same cache to
perform lookups for subsequent Lookup 3. What is generated key and generated column
transformations that share the cache. id in a normalizer transformation?
 The integration service increments the
19. What is unnamed cache and named cache? generated key sequence number each time it
 Unnamed cache: When Lookup process a source row. When the source row
transformations in a mapping have compatible contains a multiple-occurring column or a
caching structures, the Integration Service multiple-occurring group of columns, the
shares the cache by default. You can only share normalizer transformation returns a row for each
static unnamed caches. occurrence. Each row contains the same
 Named cache: Use a persistent named generated key value.
cache when you want to share a cache file  The normalizer transformation has a
across mappings or share a dynamic and a generated column ID (GCID) port for each
static cache. The caching structures must match multiple-occurring column. The GCID is an index
or be compatible with a named cache. You can for the instance of the multiple-occurring data.
share static and dynamic named caches. For example, if a column occurs 3 times in a
source record, the normalizer returns a value of
20. How do you improve the performance of 1,2 or 3 in the generated column ID.
lookup transformation? 4. What is VSAM?
 Create an index on the columns used in
the lookup condition VSAM (Virtual Storage Access Method) is a file
 Place conditions with equality operator access method for an IBM mainframe operating
first system. VSAM organize records in indexed or
sequential flat files.
 Cache small lookup tables.
 Join tables in the database: If the source 5. What is VSAM normalizer transformation?
and the lookup table are in the same database,
join the tables in the database rather than using The VSAM normalizer transformation is the
a lookup transformation. source qualifier transformation for a COBOL
 Use persistent cache for static lookups. source definition. A COBOL source is flat file
that can contain multiple-occurring data and
 Avoid ORDER BY on all columns in the multiple types of records in the same file.
lookup source. Specify explicitly the ORDER By
clause on the required columns. 6. What is pipeline normalizer transformation?
 For flat file lookups, provide Sorted files
as lookup source. Pipeline normalizer transformation processes
multiple-occurring data from relational tables or
flat files.
INFORMATICA INTERVIEW QUESTIONS ON
NORMALIZER TRANSFORMATION 7. What is occurs clause and redefines clause in
1. What is normalizer transformation? normalizer transformation?
 Occurs clause is specified when the
The normalizer transformation receives a row source row has a multiple-occurring columns.
that contains multiple-occurring columns and  A redefines clause is specified when the
retruns a row for each instance of the multiple- source has rows of multiple columns.
occurring data. This means it converts column
data in to row data. Normalizer is an active
transformation.

2. Which transformation is required to process


INFORMATICA INTERVIEW QUESTIONS ON INFORMATICA INTERVIEW QUESTIONS ON
RANK TRANSFORMATION ROUTER TRANSFORMATION
1. What is rank transformation? 1. What is a router transformation?

A rank transformation is used to select top or A router is used to filter the rows in a mapping.
bottom rank of data. This means, it selects the Unlike filter transformation, you can specify one
largest or smallest numeric value in a port or or more conditions in a router transformation.
group. Rank transformation also selects the Router is an active transformation.
strings at the top or bottom of a session sort
order. Rank transformation is an active 2. How to improve the performance of a session
transformation. using router transformation?

2. What is rank cache? Use router transformation in a mapping instead


of creating multiple filter transformations to
The integration service compares input rows in perform the same task. The router
the data cache, if the input row out-ranks a transformation is more efficient in this case.
cached row, the integration service replaces the When you use a router transformation in a
cached row with the input row. If you configure mapping, the integration service processes the
the rank transformation to rank across multiple incoming data only once. When you use multiple
groups, the integration service ranks filter transformations, the integration service
incrementally for each group it finds. The processes the incoming data for each
integration service stores group information in transformation.
index cache and row data in data cache.
3. What are the different groups in router
3. What is RANKINDEX port? transformation?

The designer creates RANKINDEX port for each The router transformation has the following
rank transformation. The integration service types of groups:
uses the rank index port to store the ranking  Input
position for each row in a group.  Output
4. How do you specify the number of rows you
want to rank in a rank transformation? 4. How many types of output groups are there?

In the rank transformation properties, there is an There are two types of output groups:
option 'Number of Ranks' for specifying the  User-defined group
number of rows you wants to rank.  Default group
5. Where you specify the filter conditions in the
5. How to select either top or bottom ranking for router transformation?
a column?
You can creat the group filter conditions in the
In the rank transformation properties, there is an groups tab using the expression editor.
option 'Top/Bottom' for selecting the top or
bottom ranking for a column. 6. Can you connect ports of two output groups
from router transformation to a single target?
6. Can we specify ranking on more than one
port? No. You cannot connect more than one output
group to one target or a single input group
No. We can specify to rank the data based on transformation.
only one port. In the ports tab, you have to
check the R option for designating the port as a
rank port and this option can be checked only on
one port.
INFORMATICA INTERVIEW QUESTIONS ON 8. What is the number of cached values set to
SEQUENCE GENERATOR default for a sequence generator
TRANSFORMATION transformation?
1. What is a sequence generator
For non-reusable sequence generators, the
transformation?
number of cached values is set to zero.
For reusable sequence generators, the number
A Sequence generator transformation generates
of cached values is set to 1000.
numeric values. Sequence generator
transformation is a passive transformation.
9. How do you configure a sequence generator
transformation?
2. What is the use of a sequence generator
transformation?
The following properties need to be configured
for a sequence generator transformation:
A sequence generator is used to create unique
 Start Value
primary key values, replace missing primary key
values or cycle through a sequential range of  Increment By
numbers.  End Value
 Current Value
3. What are the ports in sequence generator
transformation?  Cycle
 Number of Cached Values
A sequence generator contains two output ports.
They are CURRVAL and NEXTVAL.
INFORMATICA INTERVIEW QUESTIONS ON
4. What is the maximum number of sequence SORTER TRANSFORMATION
that a sequence generator can generate?
1. What is a sorter transformation?
The maximum value is
Sorter transformation is used to sort the data.
9,223,372,036,854,775,807
You can sort the data either in ascending or
descending order according to a specified sort
5. When you connect both the NEXTVAL and
key.
CURRVAL ports to a target, what will be the
output values of these ports?
2. Why sorter is an active transformation?
The output values are
As sorter transformation can suppress the
NEXTVAL CURRVAL
duplicate records in the source, it is called an
1 2
active transformation.
2 3
3 4
3. How to improve the performance of a session
4 5
using sorter transformation?
5 6
Sort the data using sorter transformation before
6. What will be the output value, if you connect
passing in to aggregator or joiner transformation.
only CURRVAL to the target without connecting
As the data is sorted, the integration service
NEXTVAL?
uses the memory to do aggregate and join
operations and does not use cache files to
The integration service passes a constant value
process the data.
for each row.

7. What will be the value of CURRVAL in a


sequence generator transformation?

CURRVAL is the sum of "NEXTVAL" and


"Increment By" Value.
INFORMATICA INTERVIEW QUESTIONS ON  Select Distinct
SOURCE QUALIFIER TRANSFORMATION  Pre-SQL
1. What is a source qualifier transformation?  Post-SQL

A source qualifier represents the rows that the


integration service reads when it runs a session. INFORMATICA INTERVIEW QUESTIONS ON
Source qualifier is an active transformation. SQL TRANSFORMATION
1. What is SQL transformation?
2. Why you need a source qualifier
SQL transformation process SQL queries
transformation?
midstream in a pipeline and you can insert,
The source qualifier transformation converts the
update, delete and retrieve rows from a
source data types into informatica native data
database.
types.

3. What are the different tasks a source qualifier 2. How do you configure a SQL transformation?
can do? The following options are required to configure
SQL transformation:
 Join two or more tables originating from
the same source (homogeneous sources)  Mode: Specifies the mode in which SQL
database. transformation runs. SQL transformation
supports two modes. They are script mode and
 Filter the rows. query mode.
 Sort the data  Database type: The type of database
 Selecting distinct values from the source that SQL transformation connects to.
 Create custom query  Connection type: Pass database
 Specify a pre-sql and post-sql connection to the SQL transformation at run time
or specify a connection object.
4. What is the default join in source qualifier 3. What are the different modes in which a SQL
transformation? transformation runs?
SQL transformation runs in two modes. They
The source qualifier transformation joins the are:
tables based on the primary key-foreign key  Script mode: The SQL transformation
relationship. runs scripts that are externally located. You can
pass a script name to the transformation with
5. How to create a custom join in source qualifier each input row. The SQL transformation outputs
transformation? one row for each input row.
 Query mode: The SQL transformation
When there is no primary key-foreign key executes a query that you define in a query
relationship between the tables, you can specify editor. You can pass parameters to the query to
a custom join using the 'user-defined join' option define dynamic queries. You can output multiple
in the properties tab of source qualifier. rows when the query has a SELECT statement.

6. How to join heterogeneous sources and flat 4. In which cases the SQL transformation
files? becomes a passive transformation and active
transformation?
Use joiner transformation to join heterogeneous If you run the SQL transformation in script mode,
sources and flat files then it becomes passive transformation. If you
run the SQL transformation in the query mode
7. How do you configure a source qualifier and the query has a SELECT statement, then it
transformation? becomes an active transformation.
 SQL Query
 User-Defined Join 5. When you configure an SQL transformation to
 Source Filter run in script mode, what are the ports that the
designer adds to the SQL transformation?
 Number of Sorted Ports
The designer adds the following ports to the 10. When you enable the NumRowsAffected
SQL transformation in script mode: output port in script mode, what will be the
 ScriptName: This is an input port. output?
ScriptName receives the name of the script to In script mode, the NumRowsAffected port
execute the current row. always returns NULL.
 ScriptResult: This is an output port.
ScriptResult returns PASSED if the script 11. How do you limit the number of rows
execution succeeds for the row. Otherwise it returned by the select statement?
returns FAILED. You can limit the number of rows by configuring
the Max Output Row Count property. To
 ScriptError: This is an output port. configure unlimited output rows, set Max Output
ScriptError returns the errors that occur when a Row Count to zero.
script fails for a row.

6. What are the types of SQL queries you can INFORMATICA INTERVIEW QUESTIONS ON
specify in the SQL transformation when you use STORED PROCEDURE TRANSFORMATION
it in query mode. 1. What is a stored procedure?
 Static SQL query: The query statement
does not change, but you can use query A stored procedure is a precompiled collection
parameters to change the data. The integration of database procedural statements. Stored
service prepares the query once and runs the procedures are stored and run within the
query for all input rows. database.
 Dynamic SQL query: The query
statement can be changed. The integration 2. Give some examples where a stored
service prepares a query for each input row. procedure is used?

The stored procedure can be used to do the


7. What are the types of connections to connect
following tasks
the SQL transformation to the database
available?  Check the status of a target database
before loading data into it.
 Static connection: Configure the
connection object tin the session. You must first  Determine if enough space exists in a
create the connection object in workflow database.
manager.  Perform a specialized calculation.
 Logical connection: Pass a connection  Drop and recreate indexes.
name to the SQL transformation as input data at
run time. You must first create the connection
3. What is a connected stored procedure
object in workflow manager.
transformation?
 Full database connection: Pass the
connect string, user name, password and other The stored procedure transformation is
connection information to SQL transformation connected to the other transformations in the
input ports at run time. mapping pipeline.

8. How do you find the number of rows inserted, 4. In which scenarios a connected stored
updated or deleted in a table? procedure transformation is used?
You can enable the NumRowsAffected output  Run a stored procedure every time a
port to return the number of rows affected by the row passes through the mapping.
INSERT, UPDATE or DELETE query statements  Pass parameters to the stored
in each input row. This NumRowsAffected option procedure and receive multiple output
works in query mode. parameters.

9. What will be the output of NumRowsAffected


5. What is an unconnected stored procedure
port for a SELECT statement?
transformation?
The NumRowsAffected outout is zero for the
SELECT statement.
The stored procedure transformation is not
connected directly to the flow of the mapping. It 8. What is execution order in stored procedure
either runs before or after the session or is transformation?
called by an expression in another
transformation in the mapping. The order in which the Integration Service calls
the stored procedure used in the transformation,
6. In which scenarios an unconnected stored relative to any other stored procedures in the
procedure transformation is used? same mapping. Only used when the Stored
 Run a stored procedure before or after a Procedure Type is set to anything except
session Normal and more than one stored procedure
 Run a stored procedure once during a exists.
mapping, such as pre or post-session.
9. What is PROC_RESULT in stored procedure
 Run a stored procedure based on data transformation?
that passes through the mapping, such as when
a specific port does not contain a null value. PROC_RESULT is a system variable, where the
 Run nested stored procedures. output of an unconnected stored procedure
 Call multiple times within a mapping. transformation is assigned by default.

10. What are the parameter types in a stored


7. What are the options available to specify procedure?
when the stored procedure transformation needs
to be run? There are three types of parameters exist in a
stored procedure:
The following options describe when the stored
 IN: Input passed to the stored procedure
procedure transformation runs:
 Normal: The stored procedure runs  OUT: Output returned from the stored
where the transformation exists in the mapping procedure
on a row-by-row basis. This is useful for calling  INOUT: Defines the parameter as both
the stored procedure for each row of data that input and output. Only Oracle supports this
passes through the mapping, such as running a parameter type.
calculation against an input port. Connected
stored procedures run only in normal mode.
INFORMATICA INTERVIEW QUESTIONS ON
 Pre-load of the Source: Before the
TRANSACTION CONTROL
session retrieves data from the source, the
TRANSFORMATION
stored procedure runs. This is useful for
verifying the existence of tables or performing 1. What is a transaction control transformation?
joins of data in a temporary table.
 Post-load of the Source: After the A transaction is a set of rows bound by a commit
session retrieves data from the source, the or rollback of rows. The transaction control
stored procedure runs. This is useful for transformation is used to commit or rollback a
removing temporary tables. group of rows.
 Pre-load of the Target: Before the
2. What is the commit type if you have a
session sends data to the target, the stored
transaction control transformation in the
procedure runs. This is useful for verifying target
mapping?
tables or disk space on the target system.
 Post-load of the Target: After the The commit type is "user-defined".
session sends data to the target, the stored
procedure runs. This is useful for re-creating 3. What are the different transaction levels
indexes on the database. available in transaction control transformation?
The following are the transaction levels or built-
A connected stored procedure transformation in variables:
runs only in Normal mode. A unconnected  TC_CONTINUE_TRANSACTION: The
stored procedure transformation runs in all the Integration Service does not perform any
above modes. transaction change for this row. This is the
default value of the expression.
 TC_COMMIT_BEFORE: The Integration  The Union transformation does not
Service commits the transaction, begins a new remove duplicate rows. To remove duplicate
transaction, and writes the current row to the rows, you must add another transformation such
target. The current row is in the new transaction. as a Router or Filter transformation.
 TC_COMMIT_AFTER: The Integration  You cannot use a Sequence Generator
Service writes the current row to the target, or Update Strategy transformation upstream
commits the transaction, and begins a new from a Union transformation.
transaction. The current row is in the committed  The Union transformation does not
transaction. generate transactions.
 TC_ROLLBACK_BEFORE: The 4. Why union transformation is an active
Integration Service rolls back the current transformation?
transaction, begins a new transaction, and
writes the current row to the target. The current Union is an active transformation because it
row is in the new transaction. combines two or more data streams into one.
 TC_ROLLBACK_AFTER: The Though the total number of rows passing into
Integration Service writes the current row to the the Union is the same as the total number of
target, rolls back the transaction, and begins a rows passing out of it, and the sequence of rows
new transaction. The current row is in the rolled from any given input stream is preserved in the
back transaction. output, the positions of the rows are not
preserved, i.e. row number 1 from input stream
1 might not be row number 1 in the output
INFORMATICA INTERVIEW QUESTIONS ON stream. Union does not even guarantee that the
UNION TRANSFORMATION output is repeatable
1. What is a union transformation?
INFORMATICA INTERVIEW QUESTIONS ON
A union transformation is used merge data from UPDATE STRATEGY TRANSFORMATION
multiple sources similar to the UNION ALL SQL
statement to combine the results from two or 1. What is an update strategy transformation?
more SQL statements.
Update strategy transformation is used to flag
2. As union transformation gives UNION ALL source rows for insert, update, delete or reject
output, how you will get the UNION output? within a mapping. Based on this flagging each
row will be either inserted or updated or deleted
Pass the output of union transformation to a from the target. Alternatively the row can be
sorter transformation. In the properties of sorter rejected.
transformation check the option select distinct.
Alternatively you can pass the output of union 2. Why update strategy is an active
transformation to aggregator transformation and transformation?
in the aggregator transformation specify all ports
as group by ports. As update strategy transformation can reject
rows, it is called as an active transformation.
3. What are the guidelines to be followed while
using union transformation? 3. What are the constants used in update
strategy transformation for flagging the rows?
The following rules and guidelines need to be  DD_INSERT is used for inserting the
taken care while working with union rows. The numeric value is 0.
transformation:  DD_UPDATE is used for updating the
 You can create multiple input groups, rows. The numeric value is 1.
but only one output group.  DD_DELETE is used for deleting the
 All input groups and the output group rows. The numeric value is 2.
must have matching ports. The precision,  DD_REJECT is used for rejecting the
datatype, and scale must be identical across all rows. The numeric value is 3.
groups.
4. If you place an aggregator after the update
strategy transformation, how the output of forward reject rows option, the integration
aggregator will be affected? service drops rejected rows and writes them to
the session log file. If you enable row error
The update strategy transformation flags the handling, the Integration Service writes the
rows for insert, update and delete of reject rejected rows and the dropped rows to the row
before you perform aggregate calculation. How error logs. It does not generate a reject file.
you flag a particular row determines how the
aggregator transformation treats any values in
that row used in the calculation. For example, if
you flag a row for delete and then later use the
row to calculate the sum, the integration service
subtracts the value appearing in this row. If the
row had been flagged for insert, the integration
service would add its value to the sum.

5. How to update the target table without using


update strategy transformation?

In the session properties, there is an option


'Treat Source Rows As'. Using this option you
can specify whether all the source rows need to
be inserted, updated or deleted.

6. If you have an update strategy transformation


in the mapping, what should be the value
selected for 'Treat Source Rows As' option in
session properties?

The value selected for the option is 'Data


Driven'. The integration service follows the
instructions coded in the update strategy
transformation.

7. If you have an update strategy transformation


in the mapping and you did not selected the
value 'Data Driven' for 'Treat Source Rows As'
option in session, then how the session will
behave?

If you do not choose Data Driven when a


mapping contains an Update Strategy or
Custom transformation, the Workflow Manager
displays a warning. When you run the session,
the Integration Service does not follow
instructions in the Update Strategy
transformation in the mapping to determine how
to flag rows.

8. In which files the data rejected by update


strategy transformation will be written?

If the update strategy transformation is


configured to Forward Rejected Rows then the
integration service forwards the rejected rows to
next transformation and writes them to the
session reject file. If you do not select the
INFORMATICA SCENARIO BASED O_dummy=1
INTERVIEW QUESTIONS WITH ANSWERS -
PART 1 The output of expression transformation will be
col, o_count, o_dummy
I have listed the following informatica scenarios
a, 1, 1
which are frequently asked in the informatica
b, 2, 1
interviews. These scenario based questions
c, 3, 1
helps you a lot in gaining confidence in
d, 4, 1
interviews.
e, 5, 1
1. How to generate sequence numbers using
Step2: Pass the output of expression
expression transformation?
transformation to aggregator and do not specify
any group by condition. Create an output port
Solution:
O_total_records in the aggregator and assign
In the expression transformation, create a
O_count port to it. The aggregator will return the
variable port and increment it by 1. Then assign
last row by default. The output of aggregator
the variable port to an output port. In the
contains the DUMMY port which has value 1
expression transformation, the ports are:
and O_total_records port which has the value of
V_count=V_count+1
total number of records in the source.
O_count=V_count
In the aggregator transformation, the ports are
2. Design a mapping to load the first 3 rows from
O_dummy
a flat file into a target?
O_count
O_total_records=O_count
Solution:
You have to assign row numbers to each record.
The output of aggregator transformation will be
Generate the row numbers either using the
O_total_records, O_dummy
expression transformation as mentioned above
5, 1
or use sequence generator transformation.
Then pass the output to filter transformation and
Step3: Pass the output of expression
specify the filter condition as O_count <=3
transformation, aggregator transformation to
joiner transformation and join on the DUMMY
3. Design a mapping to load the last 3 rows from
port. In the joiner transformation check the
a flat file into a target?
property sorted input, then only you can connect
both expression and aggregator to joiner
Solution:
transformation.
Consider the source has the following data.
col
In the joiner transformation, the join condition
a
will be
b
O_dummy (port from aggregator transformation)
c
= O_dummy (port from expression
d
transformation)
e
The output of joiner transformation will be
Step1: You have to assign row numbers to each
col, o_count, o_total_records
record. Generate the row numbers using the
a, 1, 5
expression transformation as mentioned above
b, 2, 5
and call the row number generated port as
c, 3, 5
O_count. Create a DUMMY output port in the
d, 4, 5
same expression transformation and assign 1 to
e, 5, 5
that port. So that, the DUMMY output port
always return 1 for each row.
Step4: Now pass the ouput of joiner
transformation to filter transformation and
In the expression transformation, the ports are
specify the filter condition as O_total_records
V_count=V_count+1
(port from aggregator)-O_count(port from
O_count=V_count
expression) <=2
In the filter transformation, the filter condition will Solution:
be Use sorter transformation and sort the products
O_total_records - O_count <=2 data. Pass the output to an expression
transformation and create a dummy port
The output of filter transformation will be O_dummy and assign 1 to that port. So that, the
col o_count, o_total_records DUMMY output port always return 1 for each
c, 3, 5 row.
d, 4, 5
e, 5, 5 The output of expression transformation will be
Product, O_dummy
4. Design a mapping to load the first record from A, 1
a flat file into one table A, the last record from a B, 1
flat file into table B and the remaining records B, 1
into table C? B, 1
C, 1
Solution: C, 1
This is similar to the above problem; the first 3 D, 1
steps are same. In the last step instead of using
the filter transformation, you have to use router Pass the output of expression transformation to
transformation. In the router transformation an aggregator transformation. Check the group
create two output groups. by on product port. In the aggreagtor, create an
output port O_count_of_each_product and write
In the first group, the condition should be an expression count(product).
O_count=1 and connect the corresponding
output group to table A. In the second group, the The output of aggregator will be
condition should be O_count=O_total_records Product, O_count_of_each_product
and connect the corresponding output group to A, 1
table B. The output of default group should be B, 3
connected to table C. C, 2
D, 1
5. Consider the following products data which
contain duplicate rows. Now pass the output of expression
A transformation, aggregator transformation to
B joiner transformation and join on the products
C port. In the joiner transformation check the
C property sorted input, then only you can connect
B both expression and aggregator to joiner
D transformation.
B
The output of joiner will be
Q1. Design a mapping to load all unique product, O_dummy, O_count_of_each_product
products in one table and the duplicate rows in A, 1, 1
another table. B, 1, 3
The first table should contain the following B, 1, 3
output B, 1, 3
A C, 1, 2
D C, 1, 2
D, 1, 1
The second target should contain the following
output Now pass the output of joiner to a router
B transformation, create one group and specify the
B group condition as
B O_dummy=O_count_of_each_product. Then
C connect this group to one table. Connect the
C output of default group to another table.
INFORMATICA SCENARIO BASED
Q2. Design a mapping to load each product QUESTIONS - PART 3
once into one table and the remaining products
1. Consider the following product types data as
which are duplicated into another table.
the source.
The first table should contain the following
output
Product_id, product_type
A
10, video
B
10, Audio
C
20, Audio
D
30, Audio
40, Audio
The second table should contain the following
50, Audio
output
10, Movie
B
20, Movie
B
30, Movie
C
40, Movie
50, Movie
Solution:
60, Movie
Use sorter transformation and sort the products
data. Pass the output to an expression
Assume that there are only 3 product types are
transformation and create a variable
available in the source. The source contains 12
port,V_curr_product, and assign product port to
records and you dont know how many products
it. Then create a V_count port and in the
are available in each product type.
expression editor write
IIF(V_curr_product=V_prev_product,
V_count+1,1). Create one more variable port
Q1. Design a mapping to select 9 products in
V_prev_port and assign product port to it. Now
such a way that 3 products should be selected
create an output port O_count port and assign
from video, 3 products should be selected from
V_count port to it.
Audio and the remaining 3 products should be
selected from Movie.
In the expression transformation, the ports are
Product
Solution:
V_curr_product=product
V_count=IIF(V_curr_product=V_prev_product,V
Step1: Use sorter transformation and sort the
_count+1,1)
data using the key as product_type.
V_prev_product=product
O_count=V_count
Step2: Connect the sorter transformation to an
expression transformation. In the expression
The output of expression transformation will be
transformation, the ports will be
Product, O_count
A, 1
product_id
B, 1
product_type
B, 2
V_curr_prod_type=product_type
B, 3
V_count = IIF(V_curr_prod_type =
C, 1
V_prev_prod_type,V_count+1,1)
C, 2
V_prev_prod_type=product_type
D, 1
O_count=V_count
Now Pass the output of expression
Step3: Now connect the expression
transformation to a router transformation, create
transformaion to a filter transformation and
one group and specify the condition as
specify the filter condition as O_count<=3. Pass
O_count=1. Then connect this group to one
the output of filter to a target table.
table. Connect the output of default group to
another table.
Q2. In the above problem Q1, if the number of
products in a particular product type are less c
than 3, then you wont get the total 9 records in d
the target table. For example, see the videos e
type in the source data. Now design a mapping f
in such way that even if the number of products
in a particular product type are less than 3, then Solution:
you have to get those less number of records
from another porduc types. For example: If the Create three expression transformations with
number of products in videos are 1, then the one port each. Connect col1 from Source
reamaining 2 records should come from audios Qualifier to port in first expression
or movies. So, the total number of records in the transformation. Connect col2 from Source
target table should always be 9. Qualifier to port in second expression
transformation. Connect col3 from source
Solution: qualifier to port in third expression
transformation. Create a union transformation
The first two steps are same as above. with three input groups and each input group
should have one port. Now connect the
Step3: Connect the expression transformation expression transformations to the input groups
to a sorter transformation and sort the data and connect the union transformation to the
using the key as O_count. The ports in soter target table.
transformation will be

product_id 3. Design a mapping to convert row data into


product_type column data.
O_count (sort key) The source data looks like

Step3: Discard O_count port and connect the id, value


sorter transformation to an expression 10, a
transformation. The ports in expression 10, b
transformation will be 10, c
20, d
product_id 20, e
product_type 20, f
V_count=V_count+1
O_prod_count=V_count The target table data should look like

Step4: Connect the expression to a filter id, col1, col2, col3


transformation and specify the filter condition as 10, a, b, c
O_prod_count<=9. Connect the filter 20, d, e, f
transformation to a target table.
Solution:

2. Design a mapping to convert column data into Step1: Use sorter transformation and sort the
row data without using the normalizer data using id port as the key. Then connect the
transformation. sorter transformation to the expression
The source data looks like transformation.

col1, col2, col3 Step2: In the expression transformation, create


a, b, c the ports and assign the expressions as
d, e, f mentioned below.

The target table data should look like id


value
Col V_curr_id=id
a V_count= IIF(v_curr_id=V_prev_id,V_count+1,1)
b V_prev_id=id
O_col1= IIF(V_count=1,value,NULL)
O_col2= IIF(V_count=2,value,NULL) id, element, parent_id
O_col3= IIF(V_count=3,value,NULL) 1, A, NULL
2, B, 1
Step3: Connect the expression transformation 3, C, 1
to aggregator transformation. In the aggregator 4, D, 2
transforamtion, create the ports and assign the 5, E, 2
expressions as mentioned below. 6, F, 3
7, G, 3
id (specify group by on this port) 8, H, 4
O_col1 9, I, 4
O_col2
O_col3 I have provided the solution for this problem in
col1=MAX(O_col1) Oracle Sql query. If you are interested you
col2=MAX(O_col2) can Click Here to see the solution.
col3=MAX(O_col3)
Q2. This is an extension to the problem Q1. Let
Stpe4: Now connect the ports id, col1, col2, col3 say column C2 has null for all the rows, then C1
from aggregator transformation to the target becomes the parent of C3 and c3 is parent of
table. C4. Let say both columns c2 and c3 has null for
all the rows. Then c1 becomes the parent of c4.
Design a mapping to accommodate these type
INFORMATICA SCENARIO BASED of null conditions.
QUESTIONS - PART 4
Take a look at the following tree structure
ORACLE COMPLEX QUERIES - PART 3
diagram. From the tree structure, you can easily
derive the parent-child relationship between the The source data is represented in the form the
elements. For example, B is parent of D and E. tree structure. You can easily derive the parent-
child relationship between the elements. For
example, B is parent of D and E. As the element
A is root element, it is at level 0. B, C are at level
1 and so on.

The above tree structure data is represented in


a table as shown below.
The above tree structure data is represented in
c1, c2, c3, c4 a table as shown below.
A, B, D, H
A, B, D, I c1, c2, c3, c4
A, B, E, NULL A, B, D, H
A, C, F, NULL A, B, D, I
A, C, G, NULL A, B, E, NULL
A, C, F, NULL
Here in this table, column C1 is parent of column A, C, G, NULL
C2, column C2 is parent of column C3, column
C3 is parent of column C4. Here in this table, column C1 is parent of column
C2, column C2 is parent of column C3, column
Q1. Design a mapping to load the target table C3 is parent of column C4.
with the below data. Here you need to generate
sequence numbers for each element and then Q1. Write a query to load the target table with
you have to get the parent id. As the element "A" the below data. Here you need to generate
is at root, it does not have any parent and its sequence numbers for each element and then
parent_id is NULL. you have to get the parent id. As the element "A"
is at root, it does not have any parent and its INNER JOIN
parent_id is NULL. T2 C
ON (T3.CHILD = C.PARENT)
LEFT OUTER JOIN
id, element, lev, parent_id
T2 P
1, A, 0, NULL ON (T3.PARENT = P.PARENT)
2, B, 1, 1 ORDER BY C.SEQ;
3, C, 1, 1 Note: The unpivot function works in oracle 11g.
4, D, 2, 2
5, E, 2, 2
6, F, 2, 3 INFORMATICA SCENARIO BASED
7, G, 2, 3 QUESTIONS - PART 5
8, H, 3, 4 Q1. The source data contains only column 'id'. It
9, I, 3, 4 will have sequence numbers from 1 to 1000.
Solution: The source data looks like as
WITH t1 AS
( Id
SELECT VALUE PARENT, 1
LEV,
2
LEAD(value,1) OVER (PARTITION BY r
ORDER BY lev) CHILD 3
FROM (SELECT c1, 4
c2,
c3, 5
c4, 6
ROWNUM r 7
FROM table_name
) 8
UNPIVOT (value FOR lev IN (c1 as 0,c2 as ....
1,c3 as 2,c4 as 3))
1000
),
t2 AS
( Create a workflow to load only the Fibonacci
SELECT PARENT, numbers in the target table. The target table
LEV, data should look like as
ROWNUM SEQ
FROM Id
(SELECT DISTINCT PARENT,
LEV 1
FROM T1 2
ORDER BY LEV
)
3
), 5
T3 AS 8
(
SELECT DISTINCT PARENT, 13
CHILD .....
FROM T1
WHERE CHILD IS NOT NULL In Fibonacci series each subsequent number is
UNION ALL the sum of previous two numbers. Here assume
SELECT DISTINCT NULL,
that the first two numbers of the fibonacci series
PARENT
FROM T1 are 1 and 2.
WHERE LEV=0
) Solution:
SELECT C.SEQ Id,
T3.CHILD ELEMENT, STEP1: Drag the source to the mapping
C.LEV, designer and then in the Source Qualifier
P.SEQ PARENT_ID Transformation properties, set the number of
FROM T3 sorted ports to one. This will sort the source data
in ascending order. So that we will get the STEP1: Connect three Source Qualifier
numbers in sequence as 1, 2, 3, ....1000 transformations to the Source Definition

STEP2: Connect the Source Qualifier STEP2: Now connect all the three Source
Transformation to the Expression Qualifier transformations to the Union
Transformation. In the Expression Transformation. Then connect the Union
Transformation, create three variable ports and Transformation to the Sorter Transformation. In
one output port. Assign the expressions to the the sorter transformation sort the data based on
ports as shown below. Id port in ascending order.

Ports in Expression Transformation: STEP3: Pass the output of Sorter


id Transformation to the Expression
v_sum = v_prev_val1 + v_prev_val2 Transformation. The ports in Expression
v_prev_val1 = IIF(id=1 or id=2,1, IIF(v_sum = id, Transformation are:
v_prev_val2, v_prev_val1) )
v_prev_val2 = IIF(id=1 or id =2, 2, IIF(v_sum=id, id (input/output port)
v_sum, v_prev_val2) ) val (input port)
o_flag = IIF(id=1 or id=2,1, IIF( v_sum=id,1,0) ) v_currend_id (variable port) = id
v_count (variable port) =
STEP3: Now connect the Expression IIF(v_current_id!=v_previous_id,1,v_count+1)
Transformation to the Filter Transformation and v_previous_id (variable port) = id
specify the Filter Condition as o_flag=1 o_val (output port) = DECODE(v_count, 1,
SUBSTR(val, 1, INSTR(val,',',1,1)-1 ),
STEP4: Connect the Filter Transformation to the 2,
Target Table. SUBSTR(val, INSTR(val,',',1,1)+1,
INSTR(val,',',1,2)-INSTR(val,',',1,1)-1),
Q2. The source table contains two columns "id" 3,
and "val". The source data looks like as below SUBSTR(val, INSTR(val,',',1,2)+1),
NULL
id val )
1 a,b,c
STEP4: Now pass the output of Expression
2 pq,m,n Transformation to the Target definition. Connect
3 asz,ro,liqt id, o_val ports of Expression Transformation to
the id, val ports of Target Definition.
Here the "val" column contains comma delimited
data and has three fields in that column. For those who are interested to solve this
Create a workflow to split the fields in “val” problem in oracle sql, Click Here. The oracle sql
column to separate rows. The output should look query provides a dynamic solution where the
like as below. "val" column can have varying number of fields
in each row.
id val
1 a
1 b
1 c
2 pq
2 m
2 n
3 asz
3 ro
3 liqt

Solution:
The products table contains the below data.
SQL QUERIES INTERVIEW QUESTIONS -
ORACLE PART 1 SELECT * FROM PRODUCTS;
As a database developer, writing SQL queries, PRODUCT_ID PRODUCT_NAME
PLSQL code is part of daily life. Having a good 100 Nokia
knowledge on SQL is really important. Here i am 200 IPhone
posting some practical examples on SQL 300 Samsung
queries.
The sales table contains the following data.
To solve these interview questions on SQL
queries you have to create the products, sales SELECT * FROM SALES;
tables in your oracle database. The "Create SALE_ID PRODUCT_ID YEAR QUANTITY
Table", "Insert" statements are provided below. PRICE
1 100 2010 25
CREATE TABLE PRODUCTS 5000
( 2 100 2011 16
PRODUCT_ID INTEGER, 5000
PRODUCT_NAME VARCHAR2(30) 3 100 2012 8
); 5000
CREATE TABLE SALES 4 200 2010 10
( 9000
SALE_ID INTEGER, 5 200 2011 15
PRODUCT_ID INTEGER, 9000
YEAR INTEGER, 6 200 2012 20
Quantity INTEGER, 9000
PRICE INTEGER 7 300 2010 20
); 7000
INSERT INTO PRODUCTS VALUES ( 100, 8 300 2011 18
'Nokia'); 7000
INSERT INTO PRODUCTS VALUES ( 200, 9 300 2012 20
'IPhone'); 7000
INSERT INTO PRODUCTS VALUES ( 300,
'Samsung'); Here Quantity is the number of products sold in
INSERT INTO PRODUCTS VALUES ( 400, each year. Price is the sale price of each
'LG'); product.
INSERT INTO SALES VALUES ( 1, 100,
2010, 25, 5000); I hope you have created the tables in your
INSERT INTO SALES VALUES ( 2, 100, oracle database. Now try to solve the below
2011, 16, 5000); SQL queries.
INSERT INTO SALES VALUES ( 3, 100,
2012, 8, 5000); 1. Write a SQL query to find the products which
INSERT INTO SALES VALUES ( 4, 200, have continuous increase in sales every year?
2010, 10, 9000);
INSERT INTO SALES VALUES ( 5, 200, Solution:
2011, 15, 9000);
INSERT INTO SALES VALUES ( 6, 200, Here “Iphone” is the only product whose sales
2012, 20, 9000); are increasing every year.
INSERT INTO SALES VALUES ( 7, 300,
2010, 20, 7000); STEP1: First we will get the previous year sales
INSERT INTO SALES VALUES ( 8, 300,
for each product. The SQL query to do this is
2011, 18, 7000);
INSERT INTO SALES VALUES ( 9, 300, SELECT P.PRODUCT_NAME,
2012, 20, 7000); S.YEAR,
COMMIT; S.QUANTITY,
LEAD(S.QUANTITY,1,0) OVER (
does not have sales at all?
PARTITION BY P.PRODUCT_ID
ORDER Solution:
BY S.YEAR DESC
) “LG” is the only product which does not have
QUAN_PREV_YEAR sales at all. This can be achieved in three ways.
FROM PRODUCTS P,
SALES S Method1: Using left outer join.
WHERE P.PRODUCT_ID = S.PRODUCT_ID;
SELECT P.PRODUCT_NAME
PRODUCT_NAME YEAR QUANTITY FROM PRODUCTS P
QUAN_PREV_YEAR LEFT OUTER JOIN
Nokia 2012 8 16 SALES S
Nokia 2011 16 25 ON (P.PRODUCT_ID =
Nokia 2010 25 0 S.PRODUCT_ID);
IPhone 2012 20 15 WHERE S.QUANTITY IS NULL
IPhone 2011 15 10
IPhone 2010 10 0 PRODUCT_NAME
Samsung 2012 20 18 LG
Samsung 2011 18 20
Samsung 2010 20 0 Method2: Using the NOT IN operator.

Here the lead analytic function will get the SELECT P.PRODUCT_NAME
quantity of a product in its previous year. FROM PRODUCTS P
WHERE P.PRODUCT_ID NOT IN
STEP2: We will find the difference between the (SELECT DISTINCT PRODUCT_ID
quantities of a product with its previous year’s FROM SALES);
quantity. If this difference is greater than or
equal to zero for all the rows, then the product is PRODUCT_NAME
a constantly increasing in sales. The final query LG
to get the required result is
Method3: Using the NOT EXISTS operator.
SELECT PRODUCT_NAME
FROM SELECT P.PRODUCT_NAME
( FROM PRODUCTS P
SELECT P.PRODUCT_NAME, WHERE NOT EXISTS
S.QUANTITY – (SELECT 1 FROM SALES S WHERE
LEAD(S.QUANTITY,1,0) OVER ( S.PRODUCT_ID = P.PRODUCT_ID);

PARTITION BY P.PRODUCT_ID PRODUCT_NAME


ORDER LG
BY S.YEAR DESC
)
QUAN_DIFF
3. Write a SQL query to find the products whose
FROM PRODUCTS P,
sales decreased in 2012 compared to 2011?
SALES S
WHERE P.PRODUCT_ID = S.PRODUCT_ID
Solution:
)A
GROUP BY PRODUCT_NAME
Here Nokia is the only product whose sales
HAVING MIN(QUAN_DIFF) >= 0;
decreased in year 2012 when compared with the
sales in the year 2011. The SQL query to get the
PRODUCT_NAME
required output is
IPhone
SELECT P.PRODUCT_NAME
FROM PRODUCTS P,
2. Write a SQL query to find the products which SALES S_2012,
SALES S_2011 NVL( SUM( S.QUANTITY*S.PRICE
WHERE P.PRODUCT_ID = ), 0) TOTAL_SALES
S_2012.PRODUCT_ID FROM PRODUCTS P
AND S_2012.YEAR = 2012 LEFT OUTER JOIN
AND S_2011.YEAR = 2011 SALES S
AND S_2012.PRODUCT_ID = ON (P.PRODUCT_ID =
S_2011.PRODUCT_ID S.PRODUCT_ID)
AND S_2012.QUANTITY < GROUP BY P.PRODUCT_NAME;
S_2011.QUANTITY;
PRODUCT_NAME TOTAL_SALES
PRODUCT_NAME LG 0
Nokia IPhone 405000
Samsung 406000
4. Write a query to select the top product sold in Nokia 245000
each year?
SQL QUERIES INTERVIEW QUESTIONS -
Solution:
ORACLE PART 2
Nokia is the top product sold in the year 2010. This is continuation to my previous post, SQL
Similarly, Samsung in 2011 and IPhone, Queries Interview Questions - Oracle Part 1,
Samsung in 2012. The query for this is Where i have used PRODUCTS and SALES
tables as an example. Here also i am using the
SELECT PRODUCT_NAME, same tables. So, just take a look at the tables by
YEAR going through that link and it will be easy for you
FROM to understand the questions mentioned here.
(
SELECT P.PRODUCT_NAME, Solve the below examples by writing SQL
S.YEAR, queries.
RANK() OVER (
PARTITION BY S.YEAR 1. Write a query to find the products whose
ORDER BY S.QUANTITY quantity sold in a year should be greater than
DESC the average quantity of the product sold across
) RNK all the years?
FROM PRODUCTS P,
SALES S Solution:
WHERE P.PRODUCT_ID = S.PRODUCT_ID
) A This can be solved with the help of correlated
WHERE RNK = 1; query. The SQL query for this is
PRODUCT_NAME YEAR SELECT P.PRODUCT_NAME,
Nokia 2010 S.YEAR,
Samsung 2011 S.QUANTITY
IPhone 2012 FROM PRODUCTS P,
Samsung 2012 SALES S
WHERE P.PRODUCT_ID = S.PRODUCT_ID
5. Write a query to find the total sales of each AND S.QUANTITY >
product.? (SELECT AVG(QUANTITY)
FROM SALES S1
Solution: WHERE S1.PRODUCT_ID =
S.PRODUCT_ID
This is a simple query. You just need to group );
by the data on PRODUCT_NAME and then find
the sum of sales. PRODUCT_NAME YEAR QUANTITY
Nokia 2010 25
SELECT P.PRODUCT_NAME, IPhone 2012 20
Samsung 2012 20
Samsung 2010 20 WHERE (P.PRODUCT_ID =
S.PRODUCT_ID);
2. Write a query to compare the products sales
of "IPhone" and "Samsung" in each year? The PRODUCT_NAME YEAR RATIO
output should look like as IPhone 2011 0.333333333
IPhone 2012 0.444444444
YEAR IPHONE_QUANT SAM_QUANT IPhone 2010 0.222222222
IPHONE_PRICE SAM_PRICE Nokia 2012 0.163265306
2010 10 20 9000 Nokia 2011 0.326530612
7000 Nokia 2010 0.510204082
2011 15 18 9000 Samsung 2010 0.344827586
7000 Samsung 2012 0.344827586
2012 20 20 9000 Samsung 2011 0.310344828
7000
4. In the SALES table quantity of each product is
Solution: stored in rows for every year. Now write a query
to transpose the quantity for each product and
By using self-join SQL query we can get the display it in columns? The output should look
required result. The required SQL query is like as

SELECT S_I.YEAR, PRODUCT_NAME QUAN_2010 QUAN_2011


S_I.QUANTITY IPHONE_QUANT, QUAN_2012
S_S.QUANTITY SAM_QUANT, IPhone 10 15 20
S_I.PRICE IPHONE_PRICE, Samsung 20 18 20
S_S.PRICE SAM_PRICE Nokia 25 16 8
FROM PRODUCTS P_I,
SALES S_I, Solution:
PRODUCTS P_S,
SALES S_S Oracle 11g provides a pivot function to
WHERE P_I.PRODUCT_ID = transpose the row data into column data. The
S_I.PRODUCT_ID SQL query for this is
AND P_S.PRODUCT_ID =
S_S.PRODUCT_ID SELECT * FROM
AND P_I.PRODUCT_NAME = 'IPhone' (
AND P_S.PRODUCT_NAME = 'Samsung' SELECT P.PRODUCT_NAME,
AND S_I.YEAR = S_S.YEAR S.QUANTITY,
S.YEAR
3. Write a query to find the ratios of the sales of FROM PRODUCTS P,
a product? SALES S
WHERE (P.PRODUCT_ID = S.PRODUCT_ID)
Solution: )A

The ratio of a product is calculated as the total PIVOT ( MAX(QUANTITY) AS QUAN FOR
sales price in a particular year divide by the total (YEAR) IN (2010,2011,2012));
sales price across all years. Oracle provides
RATIO_TO_REPORT analytical function for If you are not running oracle 11g database, then
finding the ratios. The SQL query is use the below query for transposing the row
data into column data.
SELECT P.PRODUCT_NAME,
S.YEAR, SELECT P.PRODUCT_NAME,
MAX(DECODE(S.YEAR,2010,
RATIO_TO_REPORT(S.QUANTITY*S.PRICE) S.QUANTITY)) QUAN_2010,
OVER(PARTITION BY MAX(DECODE(S.YEAR,2011,
P.PRODUCT_NAME ) SALES_RATIO S.QUANTITY)) QUAN_2011,
FROM PRODUCTS P, MAX(DECODE(S.YEAR,2012,
SALES S S.QUANTITY)) QUAN_2012
FROM PRODUCTS P, )
SALES S WHERE TO_CHAR(C_DATE,'DY') = 'FRI';
WHERE (P.PRODUCT_ID = S.PRODUCT_ID)
GROUP BY P.PRODUCT_NAME; 3. Write a query to duplicate each row based on
the value in the repeat column? The input table
5. Write a query to find the number of products data looks like as below
sold in each year?

Solution: Products, Repeat


A, 3
To get this result we have to group by on year B, 5
and the find the count. The SQL query for this C, 2
question is
Now in the output data, the product A should be
SELECT YEAR, repeated 3 times, B should be repeated 5 times
COUNT(1) NUM_PRODUCTS and C should be repeated 2 times. The output
FROM SALES will look like as below
GROUP BY YEAR;

YEAR NUM_PRODUCTS Products, Repeat


2010 3 A, 3
2011 3 A, 3
2012 3 A, 3
B, 5
B, 5
B, 5
SQL QUERIES INTERVIEW QUESTIONS -
B, 5
ORACLE PART 3
B, 5
Here I am providing Oracle SQL Query Interview C, 2
Questions. If you find any bugs in the queries, C, 2
Please do comment. So, that i will rectify them.
Solution:
1. Write a query to generate sequence numbers
from 1 to the specified number N? SELECT PRODUCTS,
REPEAT FROM T,
Solution: ( SELECT LEVEL L FROM DUAL
CONNECT BY LEVEL <= (SELECT
MAX(REPEAT) FROM T)
SELECT LEVEL FROM DUAL CONNECT BY ) A
LEVEL<=&N; WHERE T.REPEAT >= A.L
ORDER BY T.PRODUCTS;
2. Write a query to display only friday dates from 4. Write a query to display each letter of the
Jan, 2000 to till now? word "SMILE" in a separate row?

Solution:
S
SELECT C_DATE, M
TO_CHAR(C_DATE,'DY') I
FROM L
( E
SELECT TO_DATE('01-JAN-2000','DD-
MON-YYYY')+LEVEL-1 C_DATE Solution:
FROM DUAL SELECT SUBSTR('SMILE',LEVEL,1) A
CONNECT BY LEVEL <= FROM DUAL
(SYSDATE - TO_DATE('01-JAN- CONNECT BY LEVEL <=LENGTH('SMILE');
2000','DD-MON-YYYY')+1)
5. Convert the string "SMILE" to Ascii values? Name, Friend_of_Firend
The output should look like as 83,77,73,76,69. sam, ram
Where 83 is the ascii value of S and so on. sam, jhon
The ASCII function will give ascii value for only
one character. If you pass a string to the ascii sam, vijaysam, anand
function, it will give the ascii value of first letter in
the string. Here i am providing two solutions to Solution:
get the ascii values of string.

Solution1: SELECT f1.name,


f2.friend_name as
friend_of_friend
SELECT SUBSTR(DUMP('SMILE'),15) FROM friends f1,
FROM DUAL; friends f2
WHERE f1.name = 'sam'
Solution2: AND f1.friend_name = f2.name;

2. This is an extension to the problem 1. In the


SELECT WM_CONCAT(A) output, you can see ram is displayed as friends
of friends. This is because, ram is mutual friend
FROM of sam and vamsi. Now extend the above query
to exclude mutual friends. The outuput should
( look as
SELECT
Name, Friend_of_Friend
ASCII(SUBSTR('SMILE',LEVEL,1)) A
sam, jhon
sam, vijay
sam, anand
FROM DUAL CONNECT BY LEVEL
<=LENGTH('SMILE') Solution:

); SELECT f1.name,
f2.friend_name as
friend_of_friend
FROM friends f1,
SQL QUERIES INTERVIEW QUESTIONS - friends f2
ORACLE PART 4 WHERE f1.name = 'sam'
AND f1.friend_name = f2.name
1. Consider the following friends table as the AND NOT EXISTS
source (SELECT 1 FROM friends f3
WHERE f3.name = f1.name
Name, Friend_Name AND f3.friend_name =
sam, ram f2.friend_name);
sam, vamsi
vamsi, ram 3. Write a query to get the top 5 products based
vamsi, jhon on the quantity sold without using the
ram, vijay row_number analytical function? The source
ram, anand data looks as

Here ram and vamsi are friends of sam; ram and


jhon are friends of vamsi and so on. Now write a Products, quantity_sold, year
query to find friends of friends of sam. For sam; A, 200, 2009
ram,jhon,vijay and anand are friends of friends. B, 155, 2009
The output should look as C, 455, 2009
D, 620, 2009
E, 135, 2009 year
F, 390, 2009 FROM
G, 999, 2010 (
H, 810, 2010 SELECT products,
I, 910, 2010 quantity_sold,
J, 109, 2010 year,
L, 260, 2010 row_number() OVER(
M, 580, 2010 PARTITION BY year
ORDER BY
quantity_sold DESC) r
Solution: from t
)A
SELECT products, WHERE r <= 5;
quantity_sold,
SQL QUERY INTERVIEW QUESTIONS - PART
year
5
FROM
( Write SQL queries for the below interview
SELECT products, questions:
quantity_sold,
year, 1. Load the below products table into the target
rownum r table.
from t
ORDER BY quantity_sold DESC CREATE TABLE PRODUCTS
)A (
WHERE r <= 5; PRODUCT_ID INTEGER,
PRODUCT_NAME VARCHAR2(30)
4. This is an extension to the problem 3. Write a );
query to produce the same output using INSERT INTO PRODUCTS VALUES ( 100,
row_number analytical function? 'Nokia');
INSERT INTO PRODUCTS VALUES ( 200,
Solution: 'IPhone');
INSERT INTO PRODUCTS VALUES ( 300,
SELECT products, 'Samsung');
quantity_sold, INSERT INTO PRODUCTS VALUES ( 400,
year 'LG');
FROM INSERT INTO PRODUCTS VALUES ( 500,
( 'BlackBerry');
SELECT products, INSERT INTO PRODUCTS VALUES ( 600,
quantity_sold, 'Motorola');
year, COMMIT;
row_number() OVER( SELECT * FROM PRODUCTS;
ORDER BY quantity_sold PRODUCT_ID PRODUCT_NAME
DESC) r 100 Nokia
from t 200 IPhone
)A 300 Samsung
400 LG
WHERE r <= 5; 500 BlackBerry
600 Motorola
5. This is an extension to the problem 3. write a The requirements for loading the target table
query to get the top 5 products in each year are:
based on the quantity sold?  Select only 2 products randomly.
Solution:  Do not select the products which are
already loaded in the target table with in the last
SELECT products, 30 days.
quantity_sold,
 Target table should always contain the CONTENT_TYPE VARCHAR2(30)
products loaded in 30 days. It should not contain );
the products which are loaded prior to 30 days. INSERT INTO CONTENTS VALUES
(1,'MOVIE');
INSERT INTO CONTENTS VALUES
(2,'MOVIE');
Solution:
INSERT INTO CONTENTS VALUES
(3,'AUDIO');
First we will create a target table. The target INSERT INTO CONTENTS VALUES
table will have an additional column (4,'AUDIO');
INSERT_DATE to know when a product is INSERT INTO CONTENTS VALUES
loaded into the target table. The target (5,'MAGAZINE');
table structure is INSERT INTO CONTENTS VALUES
(6,'MAGAZINE');
CREATE TABLE TGT_PRODUCTS COMMIT;
( SELECT * FROM CONTENTS;
PRODUCT_ID INTEGER, CONTENT_ID CONTENT_TYPE
PRODUCT_NAME VARCHAR2(30), 1 MOVIE
INSERT_DATE DATE 2 MOVIE
); 3 AUDIO
The next step is to pick 5 products randomly and 4 AUDIO
then load into target table. While selecting check 5 MAGAZINE
whether the products are there in the 6 MAGAZINE
INSERT INTO TGT_PRODUCTS The requirements to load the target table are:
SELECT PRODUCT_ID,
 Load only one content type at a time
PRODUCT_NAME,
into the target table.
SYSDATE INSERT_DATE
FROM  The target table should always contain
( only one contain type.
SELECT PRODUCT_ID,  The loading of content types should
PRODUCT_NAME follow round-robin style. First MOVIE, second
FROM PRODUCTS S AUDIO, Third MAGAZINE and again fourth
WHERE NOT EXISTS ( Movie.
SELECT 1
FROM TGT_PRODUCTS T
Solution:
WHERE T.PRODUCT_ID =
S.PRODUCT_ID
) First we will create a lookup table where we
ORDER BY DBMS_RANDOM.VALUE --Random mention the priorities for the content types. The
number generator in oracle. lookup table “Create Statement” and data is
)A shown below.

CREATE TABLE CONTENTS_LKP


WHERE ROWNUM <= 2;
(
CONTENT_TYPE VARCHAR2(30),
The last step is to delete the products from the
PRIORITY INTEGER,
table which are loaded 30 days back. LOAD_FLAG INTEGER
);
DELETE FROM TGT_PRODUCTS INSERT INTO CONTENTS_LKP
WHERE INSERT_DATE < SYSDATE - 30; VALUES('MOVIE',1,1);
INSERT INTO CONTENTS_LKP
VALUES('AUDIO',2,0);
2. Load the below CONTENTS table into the INSERT INTO CONTENTS_LKP
target table. VALUES('MAGAZINE',3,0);
COMMIT;
CREATE TABLE CONTENTS SELECT * FROM CONTENTS_LKP;
( CONTENT_TYPE PRIORITY LOAD_FLAG
CONTENT_ID INTEGER,
MOVIE 1 1
AUDIO 2 0
MAGAZINE 3 0
Here if LOAD_FLAG is 1, then it indicates which
content type needs to be loaded into the target
table. Only one content type will have
LOAD_FLAG as 1. The other content types will
have LOAD_FLAG as 0. The target table
structure is same as the source table structure.
The second step is to truncate the target table
before loading the data

TRUNCATE TABLE TGT_CONTENTS;

The third step is to choose the appropriate


content type from the lookup table to load the
source data into the target table.

INSERT INTO TGT_CONTENTS


SELECT CONTENT_ID,
CONTENT_TYPE
FROM CONTENTS
WHERE CONTENT_TYPE = (SELECT
CONTENT_TYPE FROM CONTENTS_LKP
WHERE
OAD_FLAG=1);
The last step is to update the LOAD_FLAG of
the Lookup table.
UPDATE CONTENTS_LKP
SET LOAD_FLAG = 0
WHERE LOAD_FLAG = 1;
UPDATE CONTENTS_LKP
SET LOAD_FLAG = 1
WHERE PRIORITY = (
SELECT DECODE( PRIORITY,(SELECT
MAX(PRIORITY) FROM CONTENTS_LKP) ,1
,
RIORITY+1)
FROM CONTENTS_LKP
WHERE CONTENT_TYPE = (SELECT
DISTINCT CONTENT_TYPE FROM
TGT_CONTENTS)
);

You might also like