编译时 SQL 中的单个代码问题
我在我的程序中编写了一条 SQL
SELECT ID
FROM NDA.K_FAKTURIER_KDF
WHERE FAKTURIER_KDF_KZ = ?
AND NVL(MANDANT, ' ') = (CASE ?
WHEN '01180311' THEN
'BUTLERS'
ELSE
' '
END)
,当我运行它时,出现错误
java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected CHAR got NUMBER
在调试时我发现 Java 编译器执行像
SELECT ID
FROM NDA.K_FAKTURIER_KDF
WHERE FAKTURIER_KDF_KZ = ?
AND NVL(MANDANT, ' ') = (CASE ?
WHEN 01180311 THEN
'BUTLERS'
ELSE
' '
END)`
So Java 编译器转义单个代码这样的查询,所以有人能告诉我它将如何正确运行吗?
I write a SQL
SELECT ID
FROM NDA.K_FAKTURIER_KDF
WHERE FAKTURIER_KDF_KZ = ?
AND NVL(MANDANT, ' ') = (CASE ?
WHEN '01180311' THEN
'BUTLERS'
ELSE
' '
END)
In my program when I run it I got error
java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected CHAR got NUMBER
At the time of debug I found that Java compiler execute query like
SELECT ID
FROM NDA.K_FAKTURIER_KDF
WHERE FAKTURIER_KDF_KZ = ?
AND NVL(MANDANT, ' ') = (CASE ?
WHEN 01180311 THEN
'BUTLERS'
ELSE
' '
END)`
So Java compiler escape single code so can any one tell me how it will run properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试使用PreparedStatement,并传入“01180311”作为setString参数?
Did you try using a PreparedStatement, and pass in "01180311" as a setString parameter?
假设 MANDANT 是字符字段,则对
'01180311'
值执行仅字符操作可能会阻止编译器去掉引号。尝试在表达式中将
'01180311'
更改为'0118'||'0311'
。Assuming MANDANT is a character field, then performing a character-only operation on the
'01180311'
value might prevent the compiler stripping out the quotes.Try changing
'01180311'
to'0118'||'0311'
in your expression.