a表:ke_school_student
b表:ke_school_student_contact

解决方案 »

  1.   

    感觉建库的时候是不是有外键约束的话oracle会自己改?
      

  2.   

    update ke_school_student_contact a set cardno = 
    (select cardno from ke_school_student where company_id = a.company_id and student_name = a.student_name and a.contact_kind = '01' and rownum<2)
    where exists (
      select cardno from ke_school_student where company_id = a.company_id and student_name = a.student_name and a.contact_kind = '01'
    )
      

  3.   

    update ke_school_student_contact a set cardno = 
    (select distinct cardno from ke_school_student where company_id = a.company_id and student_name = a.student_name and a.contact_kind = '01' having count(*) = 1);
      

  4.   

    个人认为这是没办法实现的,因为有可能有同名的情况,所以你一执行那个update语句就出现“单行子查询返回多于一行”的错误,要实现这样的更新,必须在你更新学生信息表时就得到旧的cardno与新的cardno的对应关系,根据这个才能更新。
      

  5.   

    先把重名的学生信息剔除出去,然后用:
     update ke_school_student_contact a set a.cardno = (select b.cardno from ke_school_student b where b.student_name = a.student_name and a.company_id = b.company_id )
    where b.student_name = a.student_name and a.company_id = b.company_id
    再想办法处理剔除的信息.