update T_search set Fields=b.Fields,SelectType=b.SelectType from T_search a,(select distinct fields,fieldsnames,selecttype from T_search where fields is not null) b where a.fieldsnames=b.fieldsnames;这语句会报错:ORA-00933 命令未正确结束语法我感决没错阿
用惯了sql server,刚学oracle谢谢各位的解答!!!

解决方案 »

  1.   

    update T_search set Fields=b.Fields,SelectType=b.SelectType from T_search a,(select distinct fields,fieldsnames,selecttype from T_search where fields is not null) b where a.fieldsnames=b.fieldsnames;
    ====>>>
    update T_search set (Fields,SelectType) = (select distinct b.fields, b.selecttype from T_search b where fieldsnames=b.fieldsnames)
    where exists (select 1 from T_search b where fieldsnames=b.fieldsnames);
    大致就是这样,确保两个字段关联后,查询是唯一的,否则会报错具体看下ORACLE的语法,ORACLE和MSSQL是不一样的
      

  2.   

    to love_2008(love2008):
    update T_search set (Fields,SelectType) = (select distinct b.fields, b.selecttype from T_search b where fieldsnames=b.fieldsnames)
    where exists (select 1 from T_search b where fieldsnames=b.fieldsnames);这还是会报错:单行子查询返回多余一个行
      

  3.   

    我要到达的效果就是在本表中用某个字段(不为空的记录去更新其他为空的记录)
    不为空的可由下面的到:
    (select distinct fields,fieldsnames,selecttype from T_search where fields is not null)
      

  4.   

    你的查询应该是根据这个字段fieldsnames以这个字段分组,不为空的记录会有几条  若是多与1条我用哪条去更新哪?
    例如fieldsnames   fields    fieldsnames
    1             空        空
    1             wwe       ee
    1             rr        tt这样的话  fieldsnames为1的且fields 不为空的有两条 我应该用哪条去更新哪
      

  5.   

    1             wwe       ee
    1             rr        tt
    没有这种情况
      

  6.   

    那有没有 fieldsnames值为1而FIELDS全部为空的还是我给你做个测试吧
      

  7.   

    SQL> select * from a;        ID      FIELD        VAL
    ---------- ---------- ----------
             1
             1          2          3
             2          3          4
             2
             2                     5
    SQL> update a set (field,val)=(select b.field,b.val from a b where a.id=b.id and b.field is not null
      2   and a.field is null)
      3  where exists(select 1 from a b where a.id=b.id and b.field is not null
      4   and a.field is null);已更新3行。SQL> select * from a;        ID      FIELD        VAL
    ---------- ---------- ----------
             1          2          3
             1          2          3
             2          3          4
             2          3          4
             2          3          4
    若是你更新后结果不对的话,说明你的数据有问题,也就是不唯一  或者有其他情况