替换数据库中的某个字符串,比如把数据库中所有的‘北京’ 替换成 ‘上海’。
怎么写一个脚本运行就可以实现。

解决方案 »

  1.   

    replace
      

  2.   

    update tmptable set city=replace(city,'北京','上海') where tmptable.city like '%北京%';
      

  3.   

    如果要替换所有的表,并且表中所有的字段。
    可以写一个存储过程。系统表user_tables, 可以获取所有表格的名称,user_tab_cols以及所有字段的名称,然后构建
    update tmptable set city=replace(city,'北京','上海') where tmptable.city like '%北京%'; 
    这样的语句来循环执行。
    select * from user_tables
    select * from user_tab_cols ,还可以根据字段类型确定哪些字段想要替换。
      

  4.   

    编写存储过程执行update tablename set city=replace(city,'北京','上海') where tablename.city like '%北京%';