update table1 set c1=(select c2 from table2 where c1.main=c2.main);

解决方案 »

  1.   

    bzszp(SongZip) 你的“ where c1.main=c2.main);”写法有问题吧~我用“update table1 set c1=(select c2 from table2,table1 where table1.main=table2.main);”这样的SQL语句,提示错误:单行子查询返回多于一个行!
      

  2.   

    我这样写:update table1 set tabel1.c1=table2.c2 where table1.main=table2.main;但是总是在“table2.main”上提示“ORA-00904: 无效列名”!
    table2.main这列是明明有的啊!!!
      

  3.   

    写个PL/SQL过程吧。
    一条一条的修改就和了嘛。
      

  4.   

    update table1 set tabel1.c1=(select table2.c2 from table2 where table1.main=table2.main);
      

  5.   

    稍许麻烦一点,写了个PL/SQL过程。
    稍加修改,还可以扩展到多列的赋值。
    -----------------------------------------------
    DECLARE
      v_MAIN    TABLE2.MAIN%TYPE;
      v_C2    TABLE2.C2%TYPE;  CURSOR c_TABLE2 IS
        SELECT MAIN, C2
          FROM TABLE2;
    BEGIN 
      OPEN c_TABLE2;
      LOOP
        FETCH c_TABLE2 INTO v_MAIN, v_C2;    UPDATE TABLE1 
         SET C1= v_C2
         WHERE MAIN= v_MAIN;    EXIT WHEN c_TABLE2%NOTFOUND;
      END LOOP;  CLOSE c_TABLE2;
    END; 
    /
    -----------------------------------------------
      

  6.   

    可以用sql生成sql办法,在sqlplus中
    假设将table_b.col2值赋给table_a.col3
    select 'update table_A  set col3='||table_b.col2||'where talbe_A.col1='||table_b.col1
    from table_a,table_b
    where table_a.col1=table_b.col1
    table_a 和table_b通过col1关联.
    执行生成的肢本