我需要在PLSQL和PGSQL中用'/net/local_folder/unknown_app_location/images‘替换'/net/local_folder/apps/images’。无论'local_folder/‘之后和'/images’之前的字符串是什么,我都想在PLSQL和PGSQL中用新字符串替换它。
Ex1:
input : '/net/local_folder/apps/images'
output: '/net/local_folder/application/images'
Ex2:
input : '/net/local_folder/applications/images'
output: '/net/local_folder/apps_folder/images'
发布于 2020-09-01 16:30:23
不能说明PostgreSQL,但是-在Oracle中,一个选择可能是
SQL> with test (col) as
2 (select '/net/local_folder/apps/images' from dual union all
3 select '/net/local_folder/applications/images' from dual
4 )
5 select col,
6 regexp_replace(col, 'local_folder/\w+/images', 'local_folder/' || '&par_folder' || '/images') result
7 from test;
Enter value for par_folder: unknown_folder
COL RESULT
------------------------------------- ----------------------------------------
/net/local_folder/apps/images /net/local_folder/unknown_folder/images
/net/local_folder/applications/images /net/local_folder/unknown_folder/images
SQL>
https://stackoverflow.com/questions/63691609
复制相似问题