简体   繁体   English

第 14 行“)”附近有问题的语法错误:SQL 语句 - SAP Hana

[英]Problematic syntax error near “)” at line 14: SQL statement - SAP Hana

I am sure that you are used to this question but nonetheless I am having trouble with my SQL script.我相信您已经习惯了这个问题,但是我的 SQL 脚本遇到了问题。 It is very frustrating.这是非常令人沮丧的。

When I execute the SQL against the SAP Hana database, I continuously receive this error:当我对 SAP Hana 数据库执行 SQL 时,我不断收到此错误:

Errors occurred while executing the SQL statement: SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near ")": line 14 col 35执行 SQL 语句时发生错误:SAP DBTech JDBC:[257]:sql 语法错误:“)”附近的语法错误:第 14 行

Let me present the SQL concerned here:让我在这里介绍一下SQL:

SELECT
  BKPF.BKTXT, BKPF.MONAT, BSEG.BELNR, BSEG.BUKRS, BSEG.DMBTR, BSEG.GJAHR, BSEG.MANDT, BSEG.PRCTR, BSEG.SAKNR, CEPCT.KTEXT, CEPCT.LTEXT, SKAT.MCOD1, SKAT.TXT20, SKAT.TXT50
FROM
  SAPPR1.BSEG
  INNER JOIN SAPPR1.BKPF ON BSEG.GJAHR = BKPF.GJAHR
  INNER JOIN SAPPR1.CEPCT ON BSEG.PRCTR = CEPCT.PRCTR
  INNER JOIN (SELECT
                SAKNR, TXT20, TXT50, MCOD1
              FROM
                SAPPR1.SKAT
              WHERE
                SPRAS not LIKE  '%[a-z0-9 .]%' ) AS SKAT_SUB ON BSEG.SAKNR = SKAT_SUB.SAKNR
WHERE
  BKPF.MONAT = (SELECT Month('?')-1)
  AND (BSEG.GJAHR = (SELECT Year('?')-1 HAVING Month('?')-1 < 4) OR BSEG.GJAHR = (SELECT Year('?') HAVING Month('?')-1 > 3))
  AND BSEG.MANDT = ?
;

Unlike other DBMS HANA does not support selecting records out of nothing.与其他 DBMS 不同,HANA支持无中生有地选择记录。 A SELECT without a FROM is not valid.没有FROMSELECT无效。

In order to create a single-row set one can use the DUMMY table.为了创建单行集,可以使用 DUMMY 表。

SELECT current_date FROM DUMMY;

creates the single-row set with the result of the function expression.使用 function 表达式的结果创建单行集。

Having said that, for comparisons a set is not required.话虽如此,对于比较来说,一组不是必需的。 Instead the function can be directly put into the expression:相反,function 可以直接放入表达式中:

WHERE
  BKPF.MONAT = (MONTH(?)-1) 

Also note that for string typed bind variables no quotation marks are required or allowed.另请注意,对于字符串类型的绑定变量,不需要或不允许使用引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM