update corp_reg r
set r.corp_code=(
select t.tech_reg_code
from t_ent_info_global t
where r.corp_name=t.ent_cname
) where exists (
select 1
from t_ent_info_global t
where r.corp_name=t.ent_cname
);分析一下执行计划,最好在 t_ent_info_global.ent_cname 上创建索引

解决方案 »

  1.   

    corp_name,ent_cname这两个字段存的是不是中文?如果是中文的话,最好再建一个ID外键,或建立索引
      

  2.   

    update corp_reg r
    set r.corp_code=(
    select t.tech_reg_code
    from t_ent_info_global t
    where r.corp_name=t.ent_cname
    ) where exists (
    select 1
    from t_ent_info_global t
    where r.corp_name=t.ent_cname
    );r.corp_name=t.ent_cname中存的是中文,我想要把两个表这两个字段如等于‘我的日记’的记录都只有一条,现在要t_ent_info_global表中的tech_reg_code更新到另一张表的corp_code中
    执行后提示“单行子查询返回多于一个行”。
      

  3.   

    update corp_reg r
    set r.corp_code=(
    select max(t.tech_reg_code)
    from t_ent_info_global t
    where r.corp_name=t.ent_cname
    ) where exists (
    select 1
    from t_ent_info_global t
    where r.corp_name=t.ent_cname
    );
      

  4.   

    update corp_reg r1 set r.corp_code
    =(select t.tech_reg_code from t_ent_info_global t,corp_reg r where r.corp_name=t.ent_cname)
    where r1主键=r主键
      

  5.   

    update corp_reg r1 set corp_code
    =(select t.tech_reg_code from t_ent_info_global t,corp_reg r where r.corp_name=t.ent_cname)
    where r1主键=r主键
    这样一定可以