Sample Header Ad - 728x90

How to use query result as REPLACE parameters

0 votes
1 answer
638 views
i'm trying to: 1- Find a string inside a lot of content 2- Replace that specific part of the string with a new one using REPLACE function like this: REPLACE(column_name, query#1, query#2) Is this possible? I already have located the exact part of the content that i want to replace SELECT post_title, SUBSTRING(post_content, LOCATE('[flv:',post_content), LOCATE(']',post_content) - LOCATE('[flv:',post_content) + 1) AS amazonlinks FROM wp_posts_duplicatedfortestonly WHERE post_content LIKE '%[flv:%' and have the new string ready in another table column: Png_Link Finally i'm trying to merge all this using the REPLACE function but it's giving me a lot of errors: UPDATE wp_posts_duplicatedfortestonly SET post_content = REPLACE(post_content, (SELECT SUBSTRING(post_content, LOCATE('[flv:',post_content), LOCATE(']',post_content) - LOCATE('[flv:',post_content) + 1) FROM (SELECT post_content FROM wp_posts_duplicatedfortestonly) AS something WHERE post_content LIKE '%[flv:%'), (SELECT Png_Link FROM VideoPlayerUdpateLinksReady WHERE Mp4_Link != '')); Something like this (only difference is i'm using 2 tables): https://www.db-fiddle.com/f/91EW2kJDc8aWJYYvw86vG9/0 Also tried with variables without any luck: SET @tblname := "wp_posts_duplicatedfortestonly"; SET @colname := "post_content"; SELECT @lookfor := SUBSTRING(post_content, LOCATE('[flv:',post_content), LOCATE(']',post_content) - LOCATE('[flv:',post_content) + 1) FROM @tblname WHERE post_content LIKE '%[flv:%'; SELECT @replacewith := Png_Link FROM VideoPlayerUdpateLinksReady WHERE Mp4_Link != ''; SET @qry = CONCAT('UPDATE ',@tblname, ' SET ', @colname, ' = REPLACE(' ,@colname, ',', @lookfor, ',',@replacewith,')'); PREPARE QUERY FROM @qry; EXECUTE QUERY; What am i'm doing wrong? Is it possible to use SELECT expressions as REPLACE function parameters or what other workaround do i have?
Asked by gallo2000sv (27 rep)
Jul 30, 2019, 06:02 PM
Last activity: Aug 1, 2019, 10:11 PM