如何使用更多单引号在mysql中插入qry [英] How to insert qry in mysql with more single quotes

查看:82
本文介绍了如何使用更多单引号在mysql中插入qry的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在单列中插入两行以上的qry插入更多单引号



我尝试过:



插入TEMP_TABLE(userid,chartid,id,qry,y1,y2)值('1','chart0','chart0','选择ef_week为文本,Sum (实际生产)作为实际生产,平均(生产效率)作为生产效率从生产效率实际生产!= 0和日期(报告日期)在'2016-01-01'和'2016-08-29'组之间由ef_week订购ef_week','实际生产','Productionefficiency')

i want insert more than two line qry insert in single column with more single quotes

What I have tried:

Insert into TEMP_TABLE(userid,chartid,id,qry,y1,y2)Values('1','chart0','chart0',' select ef_week as text,Sum(actualproduction) as actualproduction , avg (Productionefficiency) as productionefficiency from EFFICIENCY where actualproduction !=0 and date(ReportDate) between '2016-01-01' and '2016-08-29' group by ef_week order by ef_week ','actualproduction','Productionefficiency')

推荐答案

请参阅文档:

MySQL:10.1.1字符串文字 [ ^ ]

如果希望它们出现在字符串中,您必须转义引号(参见表10.1特殊Charac)以上链接中的转义序列。)
Please refer to the documentation :
MySQL: 10.1.1 String Literals[^]
You have to escape the quotes when you want them to be present in the string (see Table 10.1 Special Character Escape Sequences in above link).


使用参数化查询。这将自动处理引号,日期格式等,并通过SQL注入攻击提供良好的保护。
Use a parameterized query. That will handle quotes, date formats, etc. automagically, and also provide good protection with SQL injection attacks.


这篇关于如何使用更多单引号在mysql中插入qry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆