Get Data from the Database based on a key column.

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Get Data from the Database based on a key column.

Post by Minhajuddin »

Hi all,

We have a scenario in which we need to pass data into a DB table and get the output based on the input column.


I have a job which has

SequentialFile--------->DRS_Stage-------------->SequentialFile

I am giving this query in the inputs tab of the DRS_Stage.
And it throws up a warning " Variables are not bound correctly".
This is not the exact query. But it looks like this.

select * from emp where emID=:1


Can we use the data coming from the input link of the DRS stage as a bind variable in the Inputs tab.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

A better way would be to do a select from your table and do a lookup on your first sequential file stage based on the key and get the output.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

But here the query has a "START WITH" clause and we put the :1 in the Start with clause

Code: Select all

select customer
  from (select customer, parent_customer, customer_level
          from (select customer_number as customer,
                       parenthdqtrcustomernum as parent_customer,
                       level as customer_level
                  from customer
                start with customer_number = :1
                connect by prior parenthdqtrcustomernum =
                                 customer_number) d1
        order by customer_level desc) d2,
       (select nvl(max(customer_level), 0) as max_customer_level
          from (select customer_number as customer,
                       parenthdqtrcustomernum as parent_customer,
                       level as customer_level
                  from customer
                start with customer_number = :1
                connect by prior parenthdqtrcustomernum =
                                 customer_number)) d3
 where rownum <= 4

Initially we had a transformer which did the lookup into this table and returned rows. But now the number of rows returned for one input record is equal to four. And the transformer just gets a single match record.

Thanks for the help DSguru
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Well, instead of the DRS stage, you can use an odbc stage for direct lookup and specify that this link returns multi-row result set.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

My backend DB is Oracle.

So if I use a lookup. Will it not throw warnings if we have more than one match in the lookup table?

Thanks again.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

No. If you turn on "Multi-row result set". You should not get any warnings.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

Thanks DSguru.

But my DB is huge. So, I can't use the Lookup stage unless I make it a Sparse Lookup. I have done that. Since my input file also has a large amount of data, I was just wondering if we had any other way to implement this.


Thank you.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Consequently, you can load your value into a staging table and then use your sql query to join this staging table. Thats another way.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Minhajuddin wrote:But my DB is huge. So, I can't use the Lookup stage unless I make it a Sparse Lookup. I have done that. Since my input file also has a large amount of data, I was just wondering if we had any other way to implement this.
But you asserted that this is a server job. If it is, then an ODBC stage with multi-row return is an ideal solution, particularly if the search key is indexed in the Oracle table.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

Thanks for all your responses guys! :D

I am using a sparse lookup on the table, the performance will degrade because of this. But this the only choice I have.


Once again thank you.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It's not a server job, is it?
:roll:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply