简体   繁体   中英

Using regexp_replace in update

I have a db column report_name which will have values similar to this

000007091_PaymentRegisterReport _D x3A 975844_2012-12-26.XLS

I need to delete the space before _D in all PaymentRegisterReport with XLS extension. Could somebody help me with the regex to use inside regexp_replace function in the update statement?

Do you really need a regex to update the data? Please check the query.

update TableName
set report_name=REPLACE(report_name, ' _D' , '_D')
WHERE report_name LIKE '%PaymentRegisterReport %' AND 
  report_name LIKE '%.XLS';

The expression that you need to use is

REGEXP_REPLACE(f1, '(.*)(_PaymentRegisterReport) _D (.*)(\.XLS)$', '\1\2_D\3\4')

I am assuming that you can identify the report type by 'PaymentRegisterReport' and the file extensions will be in uppercase

You can replace the " _D" bi "_D" with a select as said techdo.

But I wrote a regex_replace as you was asking :

select regexp_replace('000007091_PaymentRegisterReport _D x3A 975844_2012-12-26.XLS','^(.*) _D(.*).XLS$','\1_D\2.XLS') from dual;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM