MERGE STATEMENT in datastage?

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
karry450
Participant
Posts: 201
Joined: Wed Nov 14, 2007 11:31 pm
Location: HYD

MERGE STATEMENT in datastage?

Post by karry450 »

Hi

Can anyone help me if we can use merge statement in userdefined sql tab in datastage server jobs?

Im getting this error

Invalid SQL SELECT statement was entered

but the same MERGE statement is getting executed at database end.

Thanks
Karthik
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yes, you can but it does get a little 'tricky' and you need to understand all of the rules the stage enforces. Since you (more than likely) don't have a good way to bind the columns in the stage unless you're doing deletes in the merge as well - I'm assuming we're talking OCI stage here, yes? - I found it easier to do the MERGE either in the before or after sql tabs and put a "do nothing" sql in the main area, one that binds all input columns (just really need one) so the stage is happy.
-craig

"You can never have too many knives" -- Logan Nine Fingers
karry450
Participant
Posts: 201
Joined: Wed Nov 14, 2007 11:31 pm
Location: HYD

MERGE STATEMENT in datastage?

Post by karry450 »

chulett wrote:Yes, you can but it does get a little 'tricky' and you need to understand all of the rules the stage enforces. Since you (more than likely) don't have a good way to bind the columns in the stage unles ...
Hi Chulett can you please help me in detail. I dont have subcription at this moment and I am unable to see your msg.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Craig,

I also do not have Premium but assume you are referring to placeholders for binding variables.

Karthik,

Can you provide the full error with associated ora code.
karry450
Participant
Posts: 201
Joined: Wed Nov 14, 2007 11:31 pm
Location: HYD

MERGE STATEMENT in datastage?

Post by karry450 »

Sainath.Srinivasan wrote:Craig,

I also do not have Premium but assume you are referring to placeholders for binding variables.

Karthik,

Can you provide the full error with associated ora code.
hi

I am not getting an ora code error Im only getting

Invalid SQL SELECT statement was entered
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Bind parameters are definitely part of it. Post your sql and let us know what stage you are using.
-craig

"You can never have too many knives" -- Logan Nine Fingers
raju_chvr
Premium Member
Premium Member
Posts: 165
Joined: Sat Sep 27, 2003 9:19 am
Location: USA

Post by raju_chvr »

Chulett,

Below is the SQL:

MERGE INTO DW_STAR_MDLN.DIM_PROGRAM_TEST A
USING DW_STG_MDLN2.STG_MCD_PROGRAM B
ON (A.PROGRAM_NAME = B.PROGRAM_SHORT_NAME AND A.PROGRAM_TYPE = B.PROGRAM_TYPE)
WHEN MATCHED THEN
UPDATE SET A.LOAD_CONTROL_SKEY =:3,
A.EVENT_TYPE =:4,
A.PROCESS_FLG =:5,
A.LOAD_TIMESTAMP =TO_TIMESTAMP(:6, 'YYYY-MM-DD HH24:MI:SS.FF3'),
A.LOAD_CONTROL_RUN_SKEY=:7
WHEN NOT MATCHED THEN
INSERT INTO
(
A.PROGRAM_SKEY,
A.PROGRAM_NAME,
A.PROGRAM_TYPE,
A.LOAD_CONTROL_SKEY,
A.EVENT_TYPE,
B.PROCESS_FLG,
A.LOAD_TIMESTAMP,
A.LOAD_CONTROL_RUN_SKEY
)
VALUES
(
DW_STAR_MDLN.PROGRAM_SKEY_SEQ.NEXTVAL,
:1,
:2,
:3,
:4,
:5,
TO_TIMESTAMP(:6, 'YYYY-MM-DD HH24:MI:SS.FF3'),
:7
)

The above we are using the 'SQL' tab and not in 'Before SQL' or 'After SQL'. The more I think about it, probably using Merge statement is a wrong design here as Merge Statement is mainly designed for Merging 2 tables and not run for each and every record in your DataStage job.

Any thoughts ??
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

You are right. Merge statement is merging two tables. In your case you use either Insert Then Update/Update Then Insert.
You are the creator of your destiny - Swami Vivekananda
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Re-read this thread. You are correct in that MERGE combines two tables, not one table and an input stream, hence the suggestion to do it before/after and trigger it with a single row into the stage.
-craig

"You can never have too many knives" -- Logan Nine Fingers
raju_chvr
Premium Member
Premium Member
Posts: 165
Joined: Sat Sep 27, 2003 9:19 am
Location: USA

Post by raju_chvr »

Thank you ...
Post Reply