update student a set 班级简称=(select 班级简称 from class where 班级名称=a.班级简称)

解决方案 »

  1.   

    update student a set 班级简称=(select 班级简称 from class where 班级名称=a.班级名称)
    我这没环境 你试试
      

  2.   

    to:chd2001(天蝎降临--千分散尽还复来)
    你写的sql能正常执行?我试过了,出错:ORA-01407:(...."班级简称") 不能用NULL更新。
      

  3.   

    我也是随便找了2个替代的表试的,搂主也实际的试试吧!
    注意,如果‘表class中的班级简称’有重复一定要用‘distinct’否则多条。
      

  4.   

    这些错误是在数据不规范的环境下出现的
    update student a set 班级简称=
     decode((select 班级简称 from class where 班级名称=a.班级名称 and rownum<2),
              null,a.班级简称,
            (select 班级简称 from class where 班级名称=a.班级名称 and rownum<2));
      

  5.   

    declare 
      cursor cur 
      is
      select * from class
    begin
      for class_info in cur
      loop
        update student set 班级简称=class_info.班级简称 
         where 班级名称=class_info.班级名称;
      end loop; 
    end;
      

  6.   

    update student a
        set 班级简称 = (select 班级简称
                          from class b
                          where a.班级名称 = b.班级名称)
    where exists (select 班级简称
                          from class b
                          where a.班级名称 = b.班级名称);拿出一个答案讨论一下,看看可不可行。
      

  7.   

    update student a
        set 班级简称 = (select 班级简称
                          from class b
                          where a.班级名称 = b.班级名称 and rownum<2) --为防止重复名称,使用rownum<2
    where exists (select 班级简称
                          from class b
                          where a.班级名称 = b.班级名称); 
    这样就可以了,楼主觉得这种脚本很高深?如何高深?请说说
      

  8.   

    licsth() ( ) 信誉:99    Blog  2006-11-24 10:48:21  得分: 0   
       
    一条sql不行吧!等高人。
    ===========
    ……
    update student a 
    set 班级简称=(select 班级简称 from class where 班级名称=a.班级名称)============
    那个表class里不会有重复的“班级名称”记录吧?有的话改为:
    update student a 
    set 班级简称=(
    select 班级简称 from class where 班级名称=a.班级名称
    where rownum=1
    )  
     
      

  9.   

    本身这个句子的逻辑的确不难,但是update不允许一下写出两个表,但只更新一个表,所以就显得很麻烦。
    至于重名一说可以不用去考虑,没有什么意义,只是想拿出来讨论一下。
    谢谢大家的参与~~