在emis.answerlib_1表中,由于失误,将列answer 里面的很多数据变成这样
Question_ID Answer
1061 abcdabcd
1062 abdabd 就是数据重复了 我想把它变成abcd、abd去除每一列里面重复的数据
Question_ID Answer
1061 abcdabcd
1062 abdabd 就是数据重复了 我想把它变成abcd、abd去除每一列里面重复的数据
解决方案 »
- 转贴-Oracle 表连接方式分析(精读)
- 跪求一快速验证手机号存在的存储过程
- 使用Database Configuration Assistant使用General Purpose模板,里面的关于默认配置是自动产生还是每次都相同?
- 超奇怪的问题,视图中的查询可以用,但是建立视图就报表或视图不存在
- 在ADO.Net中如何实验一个函数同时往两个表中插入数据
- 如何取分组后各分组的前2名?急!!!!
- 紧急问题求救
- MSSQLServer的存储过程--〉Oracle中间有一段不会请大家帮忙!
- oracle导入,导出语句的语法规则.谢谢
- 怎样用oracle8i编写.sql脚本啊?还是用其他的工具?具体怎样操作?谢谢!!
- 一个看似简单的查询,请大家帮忙看看
- 在oracle中计算数据之差
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);
1061 abcdabcd
1062 abdabd
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>
--返回值是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;
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;这样就完整了。
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