how can i write this in Oracle

  • UPDATE p

    SET p.name=m.name

    FROM

    tabl a INNER JOIN  tab2 M ON p.number=m.number

     

    How can i write equivalnet of the above sql server update statement in oracle.

     

    thanks.

  • Are you working with 3 tables aliased as p, a, and m?  I don't understand what tabl a is for.

    If that was a typo and you're really dealing with only 2 tables, this should work in Oracle:

    UPDATE p

    SET p.name = (SELECT m.name

                         FROM tab2 m 

                         WHERE m.number = p.number);

    Greg

    Greg

  • Depending on the version of Oracle, you might have to use:

    UPDATE p

       SET p.name=m.name

    FROM tabl p , tab2 m

    WHERE p.number = m.number

    Andy

  • Please tell me what version of Oracle has a FROM clause for UPDATEs?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • You should avoid "UPDATE p SET p.name = (SELECT m.name FROM tab2 m WHERE m.number = p.number);" since it will update SOME p.name to NULL: the ones for which there is no correspondent in tab2.

    Try "update (SELECT p.number, p.name m.name FROM p, m WHERE m.number = p.number) set p.name = SELECT m.name"

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply