Problem – Oracle report builder provides flexibility to create multiple queries and join those with common attribute. How does data template method help us to use multiple queries?
Solution – Data template also provides same flexibilities to list down queries in multiple sections and connect them as parent child relationship.
There are two approached available to join multiple queries in data template.
- Bind variable
- Data link method
Bind Variable most efficient and faster option. Identify the common column in parent query and use it as bind variable in child queries.
<dataQuery>
<sqlstatement name="Q1_USER">
<![CDATA[
SELECT user_id BIND_USER_ID ,user_name From fnd_user
]]>
</sqlstatement>
<sqlstatement name="Q2_RESP">
<![CDATA[
SELECT responsibility_id From fnd_user_resp_groups WHERE user_id=: BIND_USER_ID
]]>
</sqlstatement>
</dataQuery>
Data Link is another way to establish the relationship between multiple queries
<link name="USER_RESP_LINK" parentQuery="Q1_USER" parentColumn="user_id" childQuery="Q2_RESP" childColumn="user_id" condition="Q1_USER.user_id= Q2_RESP.user_id" />
XML Output
<?xml version="1.0" encoding="UTF-8" ?>
< XXXOALEARNING >
<P_CUSTOMER/>100 </P_CUSTOMER/>
<LIST_G_USER>
<G_USER>
<USERID>100</USERID>
<USERNAME>Sandeep</USERNAME>
<LIST_G_RESP>
<G_RESP>
<RESPONSIBILITY_ID>1010</ RESPONSIBILITY_ID >
<RESPONSIBILITY_ID>1020</ RESPONSIBILITY_ID >
</G_RESP>
<LIST_G_RESP>
</G_USER>
<G_USER>
<USERID>200</USERID>
<USERNAME>Deepak</USERNAME>
<LIST_G_RESP>
<G_RESP>
<RESPONSIBILITY_ID>1010</ RESPONSIBILITY_ID >
<RESPONSIBILITY_ID>1030</ RESPONSIBILITY_ID >
</G_RESP>
<LIST_G_RESP>
</G_USER>
</LIST_G_USER>
</ XXXOALEARNING >
Hello Sandeep,
ReplyDeleteI have a question for data link. Is the data link between the ending < / sqlstatement > of the fist on and before the beginning of the second < sqlstatement > or is it somewhere else? Also, once you use a data link will Q2 be like this
< sqlstatement name="Q2_RESP" >
< ! [CDATA[
SELECT responsibility_id From fnd_user_resp_groups WHERE user_id= :Q1_USER.user_id
]] >
< /sqlstatement >
< /dataQuery >
Thank you for your time and help.
Hello Dennis,
ReplyDeleteThanks for going through my post.
data link is decided based on the used BIND variable -
we can have
< sqlstatement name="Q2"> < ! [CDATA[SELECT A,B From Tabl2 WHERE user_id= X_USR_ID]] > < /sqlstatement >
< sqlstatement name="Q1"> < ! [CDATA[SELECT X From Tabl1 WHERE user_id= B]] > < /sqlstatement >
< sqlstatement name="Q3"> < ! [CDATA[SELECT Y From Tabl3 WHERE Z= A]] > < /sqlstatement >
Q3 data will be dependent on Q2 results.
Note - Bine variable A is not selected column name. This will be TAG name defined down for each column value.