我的查询是:
select a.lead_id,c.contactid,c.email,a.leadid,a.applicationid,a.appstatus,
(case when c.state in ('AL','CA','GA','IL','NM','SC','UT','MO') then 'ADF' else 'FEB' end)originator,
a.createdatetime,
concat(CONCAT(UCASE(LEFT(c.FirstName, 1)),
SUBSTRING(c.FirstName, 2)),
' ',
CONCAT(UCASE(LEFT(c.LastName, 1)),
SUBSTRING(c.LastName, 2))) as 'Name',
address,CONCAT(UCASE(LEFT(c.city, 1)),
SUBSTRING(c.city, 2)) as 'City',
state,
zipcode,
concat(CONCAT(UCASE(LEFT(c.city, 1)),
SUBSTRING(c.city, 2)) ,
' ',
state,
' ',
Zipcode)add2,SubscriberKey,b.TriggeredSendDefinitionObjectID,BounceCategory
from reports.tbl_his_bounce_tracking b join reports.tbl_his_triggeredsends k on k.ObjectID=b.TriggeredSendDefinitionObjectID
join decision.contact c on c.email=b.SubscriberKey join decision.application a using(lead_id)
where k.Name like '%Email_Disclosure%' and EventType in (4,5) and date(b.CreatedDate)>=date(date_sub(convert_tz(now(),'UTC','US/pacific'),interval 1000 day)) limit 5 ;
when I m trying to insert its output in one table :
insert into reports.NOD_Physical(lead_id,contactid,email,leadid,applicationid,appstatus,loan_originator,app_createdate,name,
Address,City,state,zipcode,Address2,createdate,TriggeredSendDefinitionObjectID,BounceCategory)
values ('"+str(i[0])+"','"+str(i[1])+"','"+str(i[2])+"','"+str(i[3])+"','"+str(i[4])+"','"+str(i[5])+"','"+str(i[6])+"','"+str(i[7])+"','"+str(i[8])+"','"+str(i[9])+"','"+str(i[10])+"','"+str(i[11])+"','"+str(i[12])+"','"+str(i[13])+"','"+str(i[14])+"','"+str(i[15])+"','"+str(i[16])"');
插入成功,但是遇到名称 Janice O'Neal ,由于 Janice O'Neal << em>'而抛出以下错误/ em>。
错误:(1064,“您的SQL语法有错误;请查阅手册 对应于您的MySQL服务器版本的正确语法, 在“尼尔”,“ 121十二橡树博士”,“拉格朗日”,“ GA”,“ 30241”,“拉格朗日”附近使用 GA 30241','janiceon'在第1行“)
答案 0 :(得分:0)
在MySQL中插入值时,'
中的撇号Janice O'Neil
应该用作''
。
尝试更改为:Janice O''Neil
,看看是否可以解决您的问题。 Source
答案 1 :(得分:0)
我得到了答案: 我的插入查询用“”括起来,当我遇到“”(撇号)时,“”本身将在该点被终止,其余部分将不会被这些引号覆盖。 这就是它抛出错误的原因。
解决方案:
dbinsert = '''insert into reports.NOD_Physical(lead_id,contactid,email,leadid,applicationid,appstatus,loan_originator,app_createdate,name,Address,City,state,zipcode,Address2,createdate,TriggeredSendDefinitionObjectID,BounceCategory) values ("'''+str(i[0])+'''","'''+str(i[1])+'''","'''+str(i[2])+'''","'''+str(i[3])+'''","'''+str(i[4])+'''","'''+str(i[5])+'''","'''+str(i[6])+'''","'''+str(i[7])+'''","'''+str(i[8])+'''","'''+str(i[9])+'''","'''+str(i[10])+'''","'''+str(i[11])+'''","'''+str(i[12])+'''","'''+str(i[13])+'''","'''+str(i[14])+'''","'''+str(i[15])+'''","'''+str(i[16])+'''");'''