Home » SQL & PL/SQL » SQL & PL/SQL » Please provide equivalent update for this merge query. (Oracle 11g)
Please provide equivalent update for this merge query. [message #605471] Thu, 09 January 2014 12:28 Go to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
Hi All,

Please provide equivalent UPDATE query for this MERGE query.

MERGE INTO GHMT_SCORE GH
    USING WEDB_REPOSITORY WR
    ON(
        WR.GSD_NO = GH.GSD_NO
        AND WR.SID_NO = GH.SID_NO
    )
    WHEN MATCHED THEN
    UPDATE  SET GH.CREATE_DATE = WR.CREATE_DATE
    WHERE GH.GSD_NO > 0
    AND GH.GH_ID = 60
    AND WR.SID_NO = 1
    AND WR.CREATE_DATE IS NOT NULL
    AND GH.PSRD = 'N'


Thanks.
Re: Please provide equivalent update for this merge query. [message #605487 is a reply to message #605471] Thu, 09 January 2014 16:09 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
Consider these equivalent SQLs:
orclz>
orclz> merge into emp using dept on(emp.deptno=dept.deptno)
  2   when matched then update set ename=dname;

14 rows merged.

orclz> rollback;

Rollback complete.

orclz> update emp set ename=(select dname from dept where dept.deptno=emp.deptno);

14 rows updated.

orclz> rollback;

Rollback complete.

orclz>

Re: Please provide equivalent update for this merge query. [message #605490 is a reply to message #605487] Thu, 09 January 2014 21:37 Go to previous messageGo to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
Hi Experts,


I have written the below.
My question was this part also to be included in the WHERE clause of sub query.
and EXISTS is required in the where clause of outer query and puttind=n that sub query in the WHERE clause.

GH.GSD_NO > 0
AND GH.GH_ID = 60
AND GH.PSRD = 'N'

Is this correct ?

UPDATE GHMT_SCORE GH
SET GH.CREATE_DATE=
( SELECT WR.CREATE_DATE
FROM WEDB_REPOSITORY WR
WHERE WR.GSD_NO = GH.GSD_NO
AND WR.SID_NO = GH.SID_NO
AND WR.SID_NO = 1
AND WR.CREATE_DATE IS NOT NULL
)
WHERE GH.GSD_NO > 0
AND GH.GH_ID = 60
AND GH.PSRD = 'N'

Please help me.

Thanks.
Re: Please provide equivalent update for this merge query. [message #605491 is a reply to message #605490] Thu, 09 January 2014 21:59 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Is this correct ?
Realize that since we don't have your tables, data, or requirements, we have no idea what is result or if it is correct or not.

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/

Re: Please provide equivalent update for this merge query. [message #605492 is a reply to message #605491] Thu, 09 January 2014 22:09 Go to previous messageGo to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
Hi,

I am not asking about the result
is this UPDATE is same to the MERGE statement.

Please help me.

Thanks.
Re: Please provide equivalent update for this merge query. [message #605493 is a reply to message #605492] Thu, 09 January 2014 22:17 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>is this UPDATE is same to the MERGE statement.
what prevents you from actually comparing the results yourself?
Previous Topic: Loops
Next Topic: User who executed the Job
Goto Forum:
  


Current Time: Wed Apr 17 22:41:30 CDT 2024