2012-08-31 5 views
1

여러 게시물에서 html 코드를 교체해야합니다.MySQL에서 HTML 행을 어떻게 바꿀 수 있습니까?

UPDATE wp_posts SET post_content = REPLACE(post_content, 'target="_top" class="text"') WHERE 'post_content' = 'class="text"' 

하지만 오류가 점점 오전 :

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') WHERE 'post_content' = 'class="text"'' at line 1

가 제대로 작동하도록 모든 솔루션이 있습니까 이것은 내가 사용하고있는 코드?

+0

어떻게 SQL을 실행합니까? –

답변

1

당신은 대체를위한 세 개의 인수가 필요합니다, 당신은 또한 당신의 WHERE 절에 LIKE를 사용해야합니다 또는 당신이 어떤 경기를받지 않습니다. 마지막으로 WHERE 절에 post_content 주위에 작은 따옴표를 사용하지 않으려합니다. 백틱이나 아무것도 사용하지 마십시오.

UPDATE wp_posts 
SET post_content = REPLACE(post_content, 'class="text"', 'target="_top" class="text"') 
WHERE post_content LIKE '%class="text"%' 
+0

감사합니다. – Vlad

3

REPLACE은 세 가지 인수를 사용합니다. 일치하는 텍스트를 바꿀 내용을 말하지 않았습니다.

1

REPLACE의 올바른 사용을 위해 manual을 살펴보십시오. 당신은 3 개 인수를 제공해야합니다

REPLACE(str, from_str, to_str)

Returns the string str with all occurrences of the string from_str replaced by the string to_str. REPLACE() performs a case-sensitive match when searching for from_str.

mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww'); 
     -> 'WwWwWw.mysql.com' 
관련 문제