在emis.answerlib_1表中,由于失误,将列answer 里面的很多数据变成这样
Question_ID   Answer 
1061          abcdabcd
1062          abdabd  就是数据重复了  我想把它变成abcd、abd去除每一列里面重复的数据

解决方案 »

  1.   


    update emis.answerlib_1 a set a.answer=( select substr(answer,1,length(answer)/2) from emis.answerlib_1 where Question_ID=a.Question_ID);
      

  2.   

    提示无法更新(emis.answerlib_1.answer)为NULL
      

  3.   

    而且并不是每一条数据都错了...只有一部分数据是列1:Question_ID  列2:Answer  
        1061       abcdabcd
        1062       abdabd  
      

  4.   

    不会吧 
    SQL> create table my(id number,name varchar2(10));Table createdSQL> insert into my values(1,'abcdabcd');1 row insertedSQL> insert into my values(2,'abcabc');1 row insertedSQL> commit;Commit completeSQL> update my a set a.name=(select substr(name,1,length(name)/2) from my where id=a.id); 2 rows updatedSQL> select * from my;        ID NAME
    ---------- ----------
             1 abcd
             2 abcSQL> 
      

  5.   

    哦 我明白了 ,这样的话 可能你要写一个函数去拆分你的Answer 字段,判断他是否重复,然后再截取
      

  6.   

    我正好有时间帮你写了个函数判断是不是重复的字符串create or replace function cc_fn(p_str varchar2) return number is
    --返回值是1为重复的字符串,0为不是重复的。
      v_lstr number;
      v_sign number := 1;
      v_fstr varchar2(10);
      v_sstr varchar2(10);
    begin
      v_lstr := length(p_str);
      if mod(v_lstr, 2) <> 0 then
        return 0;
      else
        for i in 1 .. v_lstr / 2 loop
          v_fstr := substr(p_str, i, 1);
          v_sstr := substr(p_str, v_lstr / 2 + i, 1);
          if v_fstr <> v_sstr then
            v_sign := 0;
            exit;
          end if;
        end loop;
      end if;
      return v_sign;
    end cc_fn;
      

  7.   


    update my a set a.name=(select substr(name,1,length(name)/2) from my where id=a.id) where cc_fn(a.name)=1;这样就完整了。
      

  8.   

    和他一样 没区别  提示无法更新(emis.answerlib_1.answer)为NULL
      

  9.   

    create table tb(id number,name varchar2(10));
    insert into tb values(1,'abcdabcd');
    insert into tb values(2,'abcabc');
    insert into tb values(3,'ab');
    insert into tb values(4,'aa');
    insert into tb values(5,'a');update tb
       set name = substr(name, 0, length(name) / 2)
     where substr(name, 0, length(name) / 2) =
           substr(name, length(name) / 2 + 1);select * from tb;
    --------------------
    1 1 abcd
    2 2 abc
    3 3 ab
    4 4 a
    5 5 a