请建议如何通过在10g的字符串中替换单个'/'中的多个'/'来更新列

时间:2015-03-13 13:39:35

标签: oracle oracle-sqldeveloper plsqldeveloper

IMAGE_PATH(its column name) Such type of value in column given below

 sph/images///////30_Fairhall_Court.jpeg
 sph/images///8_Furnival_Court.jpeg
 sph//images/9_Pennethorne_House.jpeg
 rbkc/images/TAVISTOCK_CRESCENT.jpeg
 haringey///images///399932thumb.jpg
 urbanchoice//images//18190862.jpg
 westminster/images//7_Glarus_Court.jpeg

我想更新所有列的行,其中有多个'/',如

sph/images/30_Fairhall_Court.jpeg
 sph/images/8_Furnival_Court.jpeg
 sph/images/9_Pennethorne_House.jpeg
 rbkc/images/TAVISTOCK_CRESCENT.jpeg
 haringey/images/399932thumb.jpg
 urbanchoice/images/18190862.jpg
 westminster/images/7_Glarus_Court.jpeg

请建议如何通过在单个'/'

中替换多个'/'来更新列

1 个答案:

答案 0 :(得分:3)

您可以使用regexp_replace。

select regexp_replace( 'sph/images///////30_Fairhall_Court.jpeg', '(/){2,}','\1' )
  from dual

sph/images/30_Fairhall_Court.jpeg

因此,您的更新声明将如下所示:

update yourtable
set filename_column = regexp_replace( filename_column, '(/){2,}','\1' )
where instr(filename_column,'//')>0