Skip to main content

sql replace text in a update



Check live the Example http://sqlfiddle.com/#!9/9d3c4

We are basing the example on a table with varchar records
CREATE TABLE uno
(
str varchar(255)
);

insert into uno VALUES ( 'anteprima/image/descriptions/555b2343cb43a-555b2343c94f3-wink_smile.gif');
insert into uno VALUES ( 'anteprima/image/descriptions/555b2343cb43a-dd3b2343c94f3-wink_smile.gif');
insert into uno VALUES ( 'anteprima/image/descriptions/555b2343cb43a-555b2343c94f3-wink_smiles.gif');
insert into uno VALUES ( 'anteprima/image/descriptions/555b2343cb43a-555b2343c94f3d-wink_smile.gif');
insert into uno VALUES ( 'anteprima/image/descriptions/555b2343cb43a-555b2343c9qdq4f3-wink_smile.gif');
___


We want to REPLACE 'anteprima/image/descriptions/' with 'image/catalog/descriptions/'
 within each record.
UPDATE uno set str = replace(str, 'anteprima/image/descriptions/', 'image/catalog/descriptions/');

It's useful, for example, to move image paths of your products in magento, opencart, prestashop and so on.

sample (used for real) query that I used in opencart due to the missing images after a migration.

UPDATE oc_product_description SET
oc_product_description.description = replace(oc_product_description.description, 'anteprima/image/descriptions/', 'image/catalog/descriptions/');

Comments

Popular posts from this blog

Moodle 3.8.1+ - path leak via errors in several files

Moodle 3.8.1+ ----------------------------------------------- File: admin/mailout-debugger.php #!/usr/bin/php Notice : Disabled. in \admin\mailout-debugger.php on line 73 File: admin/settings/appearance.php Notice : Undefined variable: hassiteconfig in \admin\settings\appearance.php on line 10 Fatal error : Uncaught Error: Call to undefined function has_any_capability() in \admin\settings\appearance.php:10 Stack trace: #0 {main} thrown in \admin\settings\appearance.php on line 10 File: admin/settings/badges.php Notice : Undefined variable: hassiteconfig in \admin\settings\badges.php on line 30 Fatal error : Uncaught Error: Call to undefined function has_any_capability() in \admin\settings\badges.php:30 Stack trace: #0 {main} thrown in \admin\settings\badges.php on line 30 File: admin/settings/courses.php Notice : Undefined variable: hassiteconfig in \admin\settings\courses.php on line 32 Fatal error : Uncaught Error: Call to undefined function

2022 - Remove (the too many) Ads from Memu launcher

Simple method Download from pureapk "MEmu Launcher2" ex: MEmu Launcher2_v6.0.9_apkpure.com Install "System app remover" (root) remove from system apps the "memu launcher 2" import the "purified" MEmu Launcher2 apk with the Memu utility ("apk" on the right toolbar) Longer method Install "Export Apk" Export the memu launcher2  Install purify https://github.com/echo-devim/purify/raw/master/Purify.apk use purify with the exported memu launcher 2 Install "System app remover" (root) remove from system apps the "memu launcher 2" import the "purified" MEmu Launcher2 apk with the Memu utility ("apk" on the right toolbar)