引号:发生语法错误。 SQLCODE=-201

quotations: A syntax error has occurred. SQLCODE=-201

我正在尝试做这样的事情:

query = (
"select mandant,posnr,"
"lieferbedingung,nrkreis_nr"
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
"and mandant <> 999;"
)

queryset += [(query, filename)]



df = pd.read_sql(query, engine.connect())

但是我得到这个错误:

SQLNumResultCols failed: [IBM][CLI Driver][IDS/UNIX64] A syntax error has occurred. SQLCODE=-201

我猜是引号引起的,但我不确定如何修改它。 我也已经尝试过不使用反斜杠

[SQL: select mandant,posnr,systemdat,fk_kto_auf,fk_kto_not1,fk_kto_not2,fk_kto_empf,fk_kto_adr5,fk_kto_adr6,fk_kto_adr7,fk_kto_adr8,fk_kto_adr9,adr_auftraggeber,anzahl_kolli,volumen,gewicht,lieferbedingung,aufdat,ankdat,versandort,modus,ladehafen,loeschhafen,bereich,nrkreis_nr from eakopf_t where posnr[10,10] = " " , and posnr[1,2] not in ("99","RE","UB") and mandant <> 999;]

你有:

query = (
"select mandant,posnr,"
"lieferbedingung,nrkreis_nr"
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
"and mandant <> 999;"
)

没有 space 将 nrkreis_nrfrom 分开,因此打印的查询将包含:

select mandant,posnr,lieferbedingung,nrkreis_nrfrom eakopf_t where …

可能最好将 spaces 放在每个续行的开头(或结尾):

query = (
"select mandant, posnr,"
" lieferbedingung, nrkreis_nr"
" from eakopf_t where posnr[10,10] = \" \" and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
" and mandant <> 999;"
)

当一行的末尾或下一行的开头有标点符号时不需要(因此字符串第一行末尾的逗号表示开头的space下一行不是强制性的),但它是最安全的。

我还删除了一个逗号和 space in:

"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"