字符串修改

fqli1610 2010-12-13 06:26:18
表中有一字段:object_id
因为该字段的记录出错,需修改更新,

举其中一个记录为例,表中记录为:10-002-2010-2135,正确应该是:10-123-2010-2135

即是说,字段中记录002都需改为123

update 语句如何写...
...全文
146 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangren 2010-12-14
  • 打赏
  • 举报
回复
--如果位置不固定的话,replace函数简洁,如果情况很复杂,用正则不错
update t set object_id = regexp_replace(object_id,'-002-','-123-');
yyq02271982 2010-12-14
  • 打赏
  • 举报
回复
update aa set a = replace(a,'002','123') where a like '%002%';
yyq02271982 2010-12-14
  • 打赏
  • 举报
回复
select replace(a,'002','123') from aa where a like '%002%'
minitoy 2010-12-14
  • 打赏
  • 举报
回复
呵呵,如果是位置固定的话用replace不能保证只更新4-6位.正则好像可以做到,不过我写不出来
心中的彩虹 2010-12-14
  • 打赏
  • 举报
回复
[Quote=引用楼主 fqli1610 的回复:]
表中有一字段:object_id
因为该字段的记录出错,需修改更新,

举其中一个记录为例,表中记录为:10-002-2010-2135,正确应该是:10-123-2010-2135

即是说,字段中记录002都需改为123,

update 语句如何写...
[/Quote]

update tb set object_id=replace(object_id,'-002-','-123-')


coolkisses 2010-12-13
  • 打赏
  • 举报
回复
这个问题好像还算比较简单,上面的解答都可以
jisg_57 2010-12-13
  • 打赏
  • 举报
回复
update #T set object_id = replace(object_id,'-002-','-123-')
arsenal1999 2010-12-13
  • 打赏
  • 举报
回复
如果多的话为什么不用replace(str,str1,str2);呢
hong1987 2010-12-13
  • 打赏
  • 举报
回复
支持3楼
Oraclefans_ 2010-12-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 fqli1610 的回复:]
表中有一字段:object_id
因为该字段的记录出错,需修改更新,

举其中一个记录为例,表中记录为:10-002-2010-2135,正确应该是:10-123-2010-2135

即是说,字段中记录002都需改为123,

update 语句如何写...
[/Quote]
大哥开了个玩笑。。。。哈哈。。
Oraclefans_ 2010-12-13
  • 打赏
  • 举报
回复
-----如此简单。。。呵呵。。。。
update table t
set t.object_id = '10-123-2010-2135'
where t.object_id = '10-002-2010-2135';
minitoy 2010-12-13
  • 打赏
  • 举报
回复
update table t set t.object_id=substr(t.object_id,1,3)||'123'||substr(t.object_id,7)
where substr(t.object_id,4,3)='002'
minitoy 2010-12-13
  • 打赏
  • 举报
回复
update table t set t.object_id=substr(t.object_id,1,3)||'123'||substr(t.object_id,7)
where t.object_id='10-002-2010-2135'

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧