使用 Python 从 SAP Hana 加载数据时出现语法错误

我在通过 Python 从 SAP HANA 加载数据时遇到问题。代码在以下情况下工作正常:


connection = pyhdb.connect(|||credentials|||)

cursor = connection.cursor()

cursor.execute('SELECT "0COMP_CODE", "0VENDOR", "0REF_DOC_NO", "0BBP_INV_ID" FROM  "_SYS_BIC"."system-local.bw.bw2hana/ZFGL01MY" WHERE CAST( "0PSTNG_DATE" AS date) >= ADD_MONTHS( NEXT_DAY( LAST_DAY( CURRENT_DATE)), -2) and "0VENDOR" IS NOT NULL')

但是当我试图添加像“0COMP_CODE”='B2B'这样的条件时,


所以它看起来像这样:


Connection = pyhdb.connect(|||credentials|||)

cursor = connection.cursor()

cursor.execute('SELECT "0COMP_CODE", "0VENDOR", "0REF_DOC_NO", "0BBP_INV_ID" FROM  "_SYS_BIC"."system-local.bw.bw2hana/ZFGL01MY" WHERE CAST( "0PSTNG_DATE" AS date) >= ADD_MONTHS( NEXT_DAY( LAST_DAY( CURRENT_DATE)), -2) and "0VENDOR" IS NOT NULL AND "0COMP_CODE" = 'B2B' ')

我越来越SyntaxError: invalid syntax.


我做错了什么?


天涯尽头无女友
浏览 81回答 1
1回答

青春有我

尝试转义单引号:Connection = pyhdb.connect(|||credentials|||)cursor = connection.cursor()cursor.execute('SELECT "0COMP_CODE", "0VENDOR", "0REF_DOC_NO", "0BBP_INV_ID" FROM  "_SYS_BIC"."system-local.bw.bw2hana/ZFGL01MY" WHERE CAST( "0PSTNG_DATE" AS date) >= ADD_MONTHS( NEXT_DAY( LAST_DAY( CURRENT_DATE)), -2) and "0VENDOR" IS NOT NULL AND "0COMP_CODE" = \'B2B\' ')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python