Sam OZ
asked on
Oracle query to replace a substring
I have an oracle 11g table TB_Paths with a field pathname
I need to replace the path name as
replace all the \\KWI_Proj\ to \\kindle.com\proj\
keeping in mind that there can be following
\\KWI_Proj\123\Myproj
\\Kwi_Proj\125\Myproject
\\kwi_Proj\325\MYPROJ
in all the different cases of \\KWI_Pro it need to convert to \\kindle.com\proj\ ( without changing cases of the rest of the path
I need to replace the path name as
replace all the \\KWI_Proj\ to \\kindle.com\proj\
keeping in mind that there can be following
\\KWI_Proj\123\Myproj
\\Kwi_Proj\125\Myproject
\\kwi_Proj\325\MYPROJ
in all the different cases of \\KWI_Pro it need to convert to \\kindle.com\proj\ ( without changing cases of the rest of the path
Sam
You could use CONCAT and SUBSTR.
SELECT Pathname, CONCAT('\\kindle.com\proj\ ', SUBSTR(PathName, length('\\KWI_Proj\'))) AS New_PathName
FROM TB_Paths
You could use CONCAT and SUBSTR.
SELECT Pathname, CONCAT('\\kindle.com\proj\
FROM TB_Paths
update TB_Paths
set pathname = replace(upper(pathname), '\\KWI_PROJ\', '\\kindle.com\proj\');
--or
update TB_Paths
set pathname = regexp_replace(pathname, '\\KWI_PROJ\', '\\kindle.com\proj\', 1, 1, 'i');
Depending on the amount of data to be updates, the regexp function may take a second more ;-)
Btw: if these paths are Windows based, the case does NOT matter at all!
ASKER
hi Alex. I tried the sql. but it will convert pathname to uppercase
path is case sensitive as used in xml and used for creating uid
path is case sensitive as used in xml and used for creating uid
Here's my version as an actual UPDATE query.
UPDATE TB_Paths
SET pathname = CONCAT('\\kindle.com\proj\ ', SUBSTR(PathName, length('\\KWI_Proj\')))
UPDATE TB_Paths
SET pathname = CONCAT('\\kindle.com\proj\
but it will convert pathname to uppercaseThen use the REGEXP_REPLACE version ;-)
path is case sensitive as used in xml and used for creating uid
ASKER
Alex, can you please give your regex query
Norie, is it doing what I want?
Norie, is it doing what I want?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window