UPDATE multiple ROWS with different Values in a single statement ?
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: UPDATE multiple ROWS with different Values in a single statement ?

  1. #1
    Join Date
    Jul 2009
    Posts
    3

    UPDATE multiple ROWS with different Values in a single statement ?

    Hello,

    I need help in Updating multiple ROWS with different values using single statement. Requirement is to update one column in a table with the values in the other table.
    Say we have 3 tables, CORPORATION,CORPORATEPROFILE and MEMBER.
    Each MEMBER has CORPORATEPROFILE which inturn is associated with CORPORATION.
    Now I need to update MEMBER table with CORPORATION identifier for members who belong to corporations with identifiers say 'ABC' and 'DEF'.

    MEMBER table contains column 'CORPIDENTIFIER '.
    CORPORATEPROFILE table contains MEMBERID and CORPORATIONID,this will associate a member with the corporation.
    CORPORATION table contains ID and CORPIDENTIFIER.


    Using the below query I am getting error,ORA-01427:single-row subquery returns more than one row

    UPDATE MEMBER M SET M.CORPIDENTIFIER=
    (SELECT A.IDENTIFIER FROM CORPORATION A,CORPORATEPROFILE B
    WHERE B.CORPORATIONID=A.ID AND B.MEMBERID=M.ID AND (A.IDENTIFIER LIKE 'ABC' OR A.IDENTIFIER LIKE 'DEF'))

    Sub query in the above query returns multiple rows and hence it is throwing the error.More than one members are associated with Corporations ABC and DEF.
    Is there any way possible to update all the rows in single query with out iterating the result set of sub query.

    Please advice.

    Thanks,

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,554
    Quote Originally Posted by paho View Post
    ORA-01427:single-row subquery returns more than one row

    Sub query in the above query returns multiple rows and hence it is throwing the error.More than one members are associated with Corporations ABC and DEF.
    Either the business specifications are wrong or the query is wrongly coded.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width