How to UPDATE one column using another column in another table? SQL Error: ORA-00933: SQL command not properly ended

前端 未结 4 559
余生分开走
余生分开走 2021-01-17 08:43

I have tried everything I can think of but couldn\'t solve this SQL error:

SQL Error: ORA-00933: SQL command not properly ended

相关标签:
4条回答
  • 2021-01-17 09:13

    If you want to update rows from a subquery with more than one record you can use the merge commenad:

    merge into SALES_DATA_FAMILY_2007 A
    using (select POG_ID , FAMILY
                     FROM POG_HIERARCHY ) B
    on (A.FAMILY_ID=B.FAMILY)
    when matched then
    update set A.POG_ID=B.POG_ID
    
    0 讨论(0)
  • 2021-01-17 09:22

    Try this:

    UPDATE SALES_DATA_FAMILY_2007 A
    SET A.POG_ID =
    (   
      SELECT P.POG_ID 
      FROM POG_HIERARCHY P
      WHERE A.FAMILY_ID = P.FAMILY_ID 
    )
    
    0 讨论(0)
  • 2021-01-17 09:22
    UPDATE SALES_DATA_FAMILY_2007 A 
    SET A.POG_ID= (select B.POG_ID 
                     FROM POG_HIERARCHY B  
                    WHERE A.FAMILY_ID=B.FAMILY)
    WHERE A.POG_ID IN (SELECT C.POG_ID FROM POG_HIERARCHY C
                       WHERE A.FAMILY_ID = C.FAMILY);
    
    0 讨论(0)
  • 2021-01-17 09:26
    UPDATE SALES_DATA_FAMILY_2007 A 
    SET A.POG_ID= (select B.POG_ID 
                     FROM POG_HIERARCHY B  
                    WHERE A.FAMILY_ID=B.FAMILY) ;
    

    This will work if and only if there's at most one corresponding row in POD_HIERARCHY for a given FAMILY. If there's more than one row in POD_HIERARCHY, then you need to determine which row from POD_HIERARCHY you wish to use the value from.

    0 讨论(0)
提交回复
热议问题