Mysql执行简单代码时出错

时间:2014-03-07 16:13:51

标签: mysql sql

我用一个已经有效的函数发出了一个SQL请求,看起来像这样:

SELECT fnStripTags('this <html>is <b>a test</b>, nothing more</html>');

执行此SQL代码时:

INSERT INTO `ps_product_lang` (`description`) VALUES (
    SELECT fnStripTags(description) FROM ps_product_lang 
    WHERE ps_product_lang.id_lang = id_lang AND ps_product_lang.id_product = id_product 
) WHERE description IS NOT NULL

我收到了这个错误:

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 'SELECT fnStripTags(ps_product_lang.description) FROM
ps_product_lang WHERE ps_pr' at line 1

2 个答案:

答案 0 :(得分:0)

insert-select语句中没有values个关键字:

INSERT INTO ps_product_lang (description) 
SELECT      fnStripTags(description) 
FROM        ps_product_lang 
WHERE       ps_product_lang.id_lang = id_lang AND 
            ps_product_lang.id_product = id_product AND
            description IS NOT NULL

答案 1 :(得分:0)

试试这个..插入语句

需要values
INSERT INTO ps_product_lang (description)
  SELECT fnStripTags(description)
   FROM ps_product_lang
   WHERE ps_product_lang.id_lang = id_lang
     AND ps_product_lang.id_product = id_product
       And description IS NOT NULL