mysql查询在查询中添加单引号

时间:2014-03-24 07:54:54

标签: mysql

需要有关如何将以下查询结果转换为以下内容的建议: 使用philips,led和tv进行单引号。

insert into company_rawdata_split select 2,splits from (select NULL splits union select 'philips' union select 'led' union select 'tv') A where splits IS NOT NULL;

查询:

select concat
    ('insert into company_rawdata_split select ',id,',splits from (select NULL splits union select ',
    replace(complaint_against  ,' ',  ' union select '),') A where splits IS NOT NULL;'
    ) ProdCatQueries from company_rawdata_new

结果

insert into company_rawdata_split select 2,splits from (select NULL splits union select philips union select led union select tv) A where splits IS NOT NULL;

1 个答案:

答案 0 :(得分:0)

以下内容应该可以完成您的尝试。只是通过放置一些转义的单引号\'

来解决这个问题。

select concat ('insert into company_rawdata_split select ',id,',splits from (select NULL splits union select \'', replace(complaint_against ,' ', '\' union select \''),'\') A where splits IS NOT NULL;' ) ProdCatQueries from company_rawdata_new